0

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'

greg
  • 1
  • 2

1 Answers1

0

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.

Pascal
  • 812
  • 7
  • 19
  • I use virtualenv (installed from pip) and I try to run problematic script in VS Code. It works sometimes when I run script from terminal (like python main.py). The shebang is set to use python interpreter from virtualen vironment – greg Jun 17 '21 at 15:31