How to make conda recognize pip installed python packages? - pip

I have created a conda environnmennt
and then pip installed tensorflow using a pip wheel. numpy was installed by pip at same stage.
When trying to install scipy,
conda wants to install numpy in parallel of pip installed numpy....?
How to make various installed be recognized by conda ?

This is what the new configuration option pip_interop_enabled, introduced in Conda v4.6 is for. It is still considered a "preview" feature, but I've had success using it:
conda config --set pip_interop_enabled true
Until this feature is released in earnest, I think it would be wise to limit its use to a per-env-basis by using the --env flag when running the above.
It should be kept in mind that preferring Conda packages is still best practice. A must read in this regard is "Using Pip in a Conda Environment".

Related

How should I install keras if I have anaconda?

Which one should I use to install keras if I have anaconda?
conda install -c conda-forge keras
&
pip install --upgrade keras
Also, what is conda-forge? Why need to do it this way?
The advantages of using conda rather than pip to install packages in your Anaconda environment(s) are that:
conda should determine what dependencies your requested package has, and install those too in one operation, and
you can then keep the installed packages up to date using the conda update command:
pip, PyPI, and setuptools?
None of this is going to help with updating packages that have been
installed from PyPI via pip, or any packages installed using python
setup.py install. conda list will give you some hints about the
pip-based Python packages you have in an environment, but it won’t do
anything special to update them.
The conda-forge channel is where you can find packages that have been built for conda but are not part of the official Anaconda distribution (yet).
See answers to this question for more detail on the two options (although bear in mind some of the answers may be out of date).

tensorflow-gpu via pip time out

I was getting time outs from pypi.python.org when running pip install --upgrade tensorflow_gpu, so I added the --verbose and --timeout 10000 params to it. It starts out fast then begins to crawl:
1% |▌ | 747kB 244bytes/s eta 2 days, 9:31:36
Is there a better way to install tensorflow-gpu when inside a virtualenv in Windows? Following the instructions from this model: https://github.com/tensorflow/models/tree/master/attention_ocr
The easiest way to install tensorflow within an environment is as follows.
Activate/Enter your python environment (e.g. for Anaconda,
activate envName).
Ensure that you are actually in your virtual/conda environment!
Use pip to install tensorflow. For CPU use pip install tensorflow and for GPU use pip install tensorflow-gpu. Don't have both installed in the same directory.
Pip should take care of the rest. Tensorflow will be downloaded along with it's dependencies from Pypi.
If you're having problems installing from pip you can try updating pip or checking your internet connection. There is also a chance that Pypi are having some minor issues on their end.
Don't forget to activate your environment before trying to import Tensorflow!
Good luck!

Installing dependencies for a pip-only package through conda

Sometimes I need to install a pip-only package into a conda environment. If I install the package using pip install, then all the dependencies for that package are installed using pip, even if they are available to conda.
I would like to install as many packages as possible through conda, so currently I use a hack to get the list of package dependencies through pip, search for all of them on conda, conda install the ones that are found, and then go through with the pip install.
Am I right to prefer installing dependencies through conda rather than pip? And if so, can anyone think of a more elegant way to solve this problem?
pip and conda are two separate package managers. Only in very rare cases package managers actually work together. In practical applications conda and pip usually do not.
In reality, mixing conda and pip packages is usually unavoidable. This often leads to a messy package management, as you describe.
In my opinion, the best and currently only proper way to solve this problem is to create a conda package for all (pypi-)packages and dependencies you want to use in your conda environments.
conda-forge is a community effort that offers an easy way to contribute your own package to the conda infrastructure. You may want to check out if your package is already available, and if not if contributing is an option for you.
Am I right to prefer installing dependencies through conda rather than pip?
Yes.
Anaconda has a blog post that discusses best practices when you have no choice but to combine conda and pip. Here's a list of guidelines from that blog post:
Best Practices Checklist
Use pip only after conda
install as many requirements as possible with conda, then use pip
pip should be run with --upgrade-strategy only-if-needed (the default)
Do not use pip with the --user argument, avoid all “users” installs
Use conda environments for isolation
create a conda environment to isolate any changes pip makes
environments take up little space thanks to hard links
care should be taken to avoid running pip in the “root” [base] environment
Recreate the environment if changes are needed
once pip has been used conda will be unaware of the changes
to install additional conda packages it is best to recreate the environment
Store conda and pip requirements in text files
package requirements can be passed to conda via the --file argument
pip accepts a list of Python packages with -r or --requirements
conda env will export or create environments based on a file with conda and pip requirements

Installing Python Package to Conda Env Without Using Conda

I have a fresh Anaconda environment in which I would like to install the latest release of mysql-connector-python (v2.1.3). I'm on a CentOS6 system. The problem is, the newest Conda-hosted package is 2.0.3 and because the connector is not currently hosted on PyPI, it cannot be installed via Pip. (Pip's --allow-external option has been deprecated.)
I know that I can easily install the package via yum install, but I believe that will install it outside of the Conda environment.
Is there any way, using yum or otherwise, to isolate this package solely to this particular Conda environment?
Turns out this is surprisingly simple. Just download the source for the Python package that is not available on PyPI and pip install at the source directory. Just remember to have the Conda environment you want to install to active and Pip will correctly isolate the install to env scope.
I was unaware of Pip's install from local options, so big thanks to the folks on the Anaconda mailing list for their help with this.

Practical difference between pip and conda

I saw other questions regarding difference between pip and conda, but it is not clear to me yet, please consider that before marking as duplicate.
If I run pip install seaborn and conda install seaborn Will I get the same result ?
I can run pip install seaborn twice without any problem, but if I run pip install and then conda install do I get the same package duplicated in two different places ?
Conda and pip cannot be used interchangeably but what are examples of that ?
Both pip and conda install the package (pretty much) with the same end result. There may be minor differences, e.g. zipped egg or not, it depends a bit on how the conda package was created. The conda package is always a compiled binary distribution though, not a source distribution.
I don't think conda will install it in different places, it may well overwrite your pip package. But it's kind of risky because conda keeps nicely track of what's installed and figures out all dependencies betweeen all conda packages in the environment. You really want to limit yourself to conda packages and only install pip packages if you really have to. It's quite easy to create conda packages though from pip packages.
Not sure about "interchangeably", you can use them alongside each other. But pip and conda are not so aware of each other so you might run into trouble with say updating packages to new versions.
In summary: if you're using conda packages, best to stick with that. You get the best out of the conda ecosystem with it's package version and environment management.

Resources