简体   繁体   English

路径存在于sys.path中,但仍然在Python中提供模块未找到错误

[英]Path exists in sys.path but still gives module not found error in Python

So, I print the sys.path in the python terminal inside the working python project directory, and find the directory there. 因此,我在工作python项目目录中的python终端中打印sys.path ,并在那里找到目录。 I've also put in a __init__.py in the directory, too. 我也在目录中输入了__init__.py

But when I do a import directoryname , I get a module not found error. 但是,当我执行import directoryname ,我得到一个模块未找到错误。

Where can I possibly be going wrong? 哪里可能出错?

Ok, I found the problem. 好的,我发现了问题。 It is giving a no such directory error when I check the $PYTHONPATH. 当我检查$ PYTHONPATH时,它给出了一个没有这样的目录错误。

This is my PythonPath 这是我的PythonPath

export PYTHONPATH=/usr/lib/python2.7/dist-packages:/home/python/softwares/orade export PYTHONPATH = / usr / lib / python2.7 / dist-packages:/ home / python / softwares / orade

I assume that you are trying to import the orade module. 我假设您正在尝试导入orade模块。 PYTHONPATH represents the path to the directory that contains python modules, not the collection of paths to the modules. PYTHONPATH表示包含python模块的目录的路径,而不是模块路径的集合。

So you should put the parent directory of your module in the PYTHONPATH . 因此,您应该将模块的父目录放在PYTHONPATH If the path to your module is /home/python/softwares/orade , you should put /home/python/softwares in your PYTHONPATH : 如果你的模块的路径是/home/python/softwares/orade ,你应该将/home/python/softwares放在你的PYTHONPATH

export PYTHONPATH=/usr/lib/python2.7/dist-packages:/home/python/softwares

And then you should be able to do: 然后你应该能够做到:

>>> import orade

If the orade directory contains a __init__.py file. 如果orade目录包含__init__.py文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM