我已经在路径“/home/user/.local/lib/python2.7/site-packages/windrose/windrose.py”中安装并将模块“windrose”加载到Python2.7。当我运行包括
的程序时from windrose import WindroseAxes
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
我收到错误消息:
Traceback (most recent call last):
File "/home/user/Documents/evaluation/my_windrose.py", line 1, in <module>
from windrose import WindroseAxes
File "/home/user/Documents/evaluation/windrose.py", line 1, in <module>
ImportError: cannot import name WindroseAxes
我猜列表sys.path包含此模块的false条目,因为Python在我的文件夹“evaluation”中搜索windrose.py。因此,我直接从正确的路径加载模块,我的程序工作正常:
from matplotlib import pyplot as plt
import matplotlib.cm as cm
import numpy as np
import imp
foo = imp.load_source('windrose', '/home/user/.local/lib/python2.7/site-packages/windrose/windrose.py')
from windrose import WindroseAxes
但这应该更容易操作!我想知道的是如何永久地将错误的路径替换为该模块的正确路径?我找到了一些用于向sys.path插入新目录的Answers,但我也不想拥有两个windrose目录。有任何想法吗?谢谢!