2016-09-24 74 views
0

我在这里问这个问题的原因是我没有在其他地方找到解决方案。在尝试运行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!") 
+1

如果你可以附加你的.py脚本,那将会很棒。 无论如何,使用任何一种虚拟环境的Python? –

+0

请显示您的代码。你需要确保你把一个合适的[mcve]放在一起,以便为读者提供必要的信息来帮助诊断你的问题。 – idjaw

+0

我现在编辑并发布代码。 – Wasp15

回答

0

你必须有一个名为os.py是正在进口的,而不是“真实的” os模块Python文件。

+0

会检查出来。 – Wasp15

+0

任何方式来找出是否os.py被替换为假的,因为我刚刚证实代码没有改变,并且它是提供错误的“OS”模块。 – Wasp15

+0

'print(os .__ file __)'将打印OS模块文件的完整路径名。 –