简体   繁体   中英

cx_Oracle not found although installed by Conda

I have a box I'm using that, for security reasons, has no internet access.

I've installed Anaconda on the box:

  • python --version # => Python 3.6.5 :: Anaconda, Inc.
  • which python #=> /home/current_user/anaconda3/bin/python

I've also installed the cx_oracle package along with the oracle-instantclient by downloading the appropriate archives and installing the packages. Proof:

$ conda install cx_oracle-6.3.1-py36h14c3975_0.tar.bz2
$ conda install oracle-instantclient-11.2.0.4.0-0.tar.bz2
$ conda list | grep oracle
cx_oracle                 6.3.1            py36h14c3975_0    <unknown>
oracle-instantclient      11.2.0.4.0                    0    <unknown>

For some reason though, Python can't find the cx_Oracle module, despite being able to find several other modules I've installed.

$ python -c "import cx_Oracle"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'cx_Oracle'

$ conda install python-dotenv-0.8.2-py_1.tar.bz2
$ python -c "import dotenv"
# => No problem
$ python -c "import cx_Oracle"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'cx_Oracle'

The cx_oracle is installed in a conda environment. It can either be conda base or conda root (depending on the version) execute:

 $ conda activate

you'll see the environment activation

(base)  $

then try again

(base)  $ python -c "import cx_Oracle"

You may also use conda info --envs to see which environments you have on the computer

I know this post is a little old, but for anyone coming across this now who's using PyCharm, my issue actually turned out to be a problem with Pycharm, not with my conda installation. Running 'conda list | grep oracle' should show if it's installed in your environment or not:

(stats-gatherer) λ conda list | grep oracle
cx_oracle                 7.1.3            py36h2fa13f4_0    /

For me, Pycharm was able to find cx_Oracle after a restart by selecting File -> Invalidate Caches / Restart.

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