我想从命令行运行一个脚本,Python是具有绝对没有它:Python的搜索路径 - Python不能找到我的模块
[graffias:~/testing.tustincommercial.com]$ export PYTHONPATH=`pwd`:$PYTHONPATH
[graffias:~/testing.tustincommercial.com]$ python -c 'import oneclickcos.mainapp; mainapp.mail.worker_loop()'
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named oneclickcos.mainapp
[graffias:~/testing.tustincommercial.com]$ python
Python 2.5.2 (r252:60911, Jan 24 2010, 17:44:40)
[GCC 4.3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import oneclickcos
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named oneclickcos
>>>
[graffias:~/testing.tustincommercial.com]$ ls ./oneclickcos/mainapp/mail.py
./oneclickcos/mainapp/mail.py
[graffias:~/testing.tustincommercial.com]$
任何想法?
注意事项:上面的命令应该是$python -c 'import oneclickcos.mainapp.mail; oneclickcos.mainapp.mail.worker_loop()'
(另一个有效的变体)。
在2.6中,我可以'导出PYTHONPATH =“/ a/b/c:/ a/b/d”'并导入这些文件夹中的模块而没有问题。除了在家里有一台特定的机器。在那个盒子里,我只能在PYTHONPATH中有一个路径,否则它不会导入任何东西。我断定那个盒子上的解释器编译不正确。也许你正面临类似的问题... – wberry
我看不到你添加到你的模块的父目录路径到'sys.path'。 –