简体   繁体   中英

How to get packages to import in code within anaconda virtualenv?

Currently I cannot import package installed in virtual environment:

Traceback (most recent call last): File "/Users/glada/GIT_REPOS/autoflux/main.py", line 5, in import cx_oracle ModuleNotFoundError: No module named 'cx_oracle'

Imports in python are sometimes a bit tricky because it depends on how you call a line of code. Do you call the import from the python REPL input?

>>> import cx_oracle

Do you call the line of code from inside a script?

$ python myscript.py

Do you run the script as a module?

$ python -m myscript

Also a folder structure would be helpful. Do you use virtualenv ? Maybe you have installed the package to the wrong location (installed in main python installation site-packages and now you are trying to import inside an activated virtualenv)?

There is a brilliant answer on a similar question , which is really descriptive and once I also found very useful to understand imports in python. Maybe this helps you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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