使用PyCharm 4.0.5在Python中编译错误

时间:2016-09-24 16:33:44

标签: python pycharm

我在这里提出问题的原因是我在其他地方找不到解决方案。在尝试运行Python脚本时,我的PyCharm 4.0.5程序出现以下错误。有一天工作正常,当我今天下午尝试使用它时,我遇到了以下错误,因为我打算运行一个程序,我100%没有错误。 在消息框中,我收到以下错误:

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 个答案:

答案 0 :(得分:0)

你必须有一个名为os.py的python文件,而不是&#34; real&#34; os模块。