我在這裏問這個問題的原因是我沒有在其他地方找到解決方案。在嘗試運行Python腳本時,我的PyCharm 4.0.5程序出現以下錯誤。它有一天工作得很好,當我今天下午嘗試使用它時,綁定後運行一個我100%沒有錯誤的程序後出現以下錯誤。 在消息框中我得到了以下錯誤:使用PyCharm與Python編譯錯誤4.0.5
Failed to import the site module
Traceback (most recent call last):
File "C:\Python34\lib\site.py", line 562, in <module>
main()
File "C:\Python34\lib\site.py", line 544, in main
known_paths = removeduppaths()
File "C:\Python34\lib\site.py", line 125, in removeduppaths
dir, dircase = makepath(dir)
File "C:\Python34\lib\site.py", line 90, in makepath
dir = os.path.join(*paths)
AttributeError: 'module' object has no attribute 'path'
Process finished with exit code 1
我從來沒有見過這樣的錯誤,不知道從哪裏開始解決這個問題。
任何反饋將不勝感激!
該代碼如下所示,我似乎忘記提及它對我的計算機上的每個.py腳本都提供了完全相同的錯誤。
import turtle
wn = turtle.Screen()
alex = turtle.Turtle()
def hexagon(var):
for i in range(6):
alex.right(60)
alex.forward(var)
def square(var):
for i in range(4):
alex.forward(var)
alex.left(90)
def triangle(var):
for i in range(3):
alex.forward(var)
alex.left(120)
def reset():
alex.clear()
alex.reset()
x = True
while x:
alex.hideturtle()
choice = input("""
Enter the shape of choice:
a. Triangle
b. Square
c. Hexagon
""")
if choice.lower() == "a":
length = input("Enter the desired length of the sides: ")
triangle(int(length))
restart = input("Do you wish to try again? Y/N ")
if restart.lower() == "n":
x = False
else:
reset()
if choice.lower() == "b":
length = input("Enter the desired length of the sides: ")
square(int(length))
restart = input("Do you wish to try again? Y/N ")
if restart.lower() == "n":
x = False
else:
reset()
if choice.lower() == "c":
length = input("Enter the desired length of the sides: ")
hexagon(int(length))
restart = input("Do you wish to try again? Y/N ")
if restart.lower() == "n":
x = False
else:
reset()
print("Thank you for using your local turtle services!")
如果你可以附加你的.py腳本,那將會很棒。 無論如何,使用任何一種虛擬環境的Python? –
請顯示您的代碼。你需要確保你把一個合適的[mcve]放在一起,以便爲讀者提供必要的信息來幫助診斷你的問題。 – idjaw
我現在編輯併發布代碼。 – Wasp15