Python module import error

2019-09-06 04:28发布

when i am importing some modules from python shell, import work fine: for example: (link for propy module https://code.google.com/p/protpy/downloads/list)

>>> import propy
>>>

but when i write script with python Default IDLE or with other IDE and save it to as .py script , import statements not work and generate error like this

python fragment_generator.py

>>> 
Traceback (most recent call last):
  File "J:\acetylome scripts\New folder\fragment_generator.py", line 1, in <module>
    import propy
ImportError: No module named propy
>>> 

please solve it

thanks in advance:

标签: python import
1条回答
forever°为你锁心
2楼-- · 2019-09-06 04:49

When you run the shell from the same directory the files are in the import will work. You are probably working from another directory when the import fails.

you can add a directory to the python path like this.

befor your import:

import sys
sys.path.append('/path/to/your/folder')
import propy

good luck.

查看更多
登录 后发表回答