feelfree
feelfree

Reputation: 11753

python libraries managed by conda and native python

In my Ubuntu 14.04 computer, I have installed two kinds of Python, one is called native python, which comes along with the Ubuntu operating system, and the other is the conda version, which is installed after I installed the conda package.

If I launch python command, the default python refers to the conda version.

Using conda can bring a lot of advantages for package management. But before I installed conda, I have already installed some Python modules with the native Python by using pip install command. These modules, however, are not reachable by conda Python. So, here is my question: how can I set conda so that it can use the packages managed by native python?

When I ask this question, I cannot help asking another questions:

Upvotes: 1

Views: 1503

Answers (1)

brunston
brunston

Reputation: 1344

It is not a good practice to mix packages managed by conda and native python. You can still, however, install Python modules using pip into Anaconda. I would recommend strictly using Anaconda (and use conda virtual environments as well as the conda package manager), and not using native python any longer.

Your best bet is to use strictly Anaconda moving forward. I would reinstall the packages into a conda virtual environment.

conda create --name NAME_HERE

or

conda create --name NAME_HERE --clone root if you want to include all packages that come with Anaconda by default.

Then switch to your new environment with source activate NAME_HERE (Linux, macOS) or activate NAME_HERE (Windows). Then you can install packages with both the conda package manager and pip.

See the conda docs on managing conda virtual environments for details.

Kind user @MikhailKnyazev has pointed out that this is how you would use the packages managed by native python. It is still not recommended.

Although it is certainly not a good practice, it is useful to know that you can add system-side packages inside virtual environment by symlinking them like this: ln -s /usr/lib/<PYTHON_VER>/dist-packages/<PACKAGE> <virtualenv_path>/lib/<PYTHON_VER>/site-packages/

Upvotes: 2

Related Questions