Use conda or pip in intel-python? [duplicate] - python

I have installed a fresh anaconda v4.4. I realized that python packages can be installed using both conda and pip. What is the effect of using pip to install python packages instead of conda when using anaconda? Will the pip-installed libraries cease to function? I am using python v3
EDIT: I don't think the question is a duplicate of What is the difference between pip and conda?
That question explains the difference between pip and conda but does not talk about the effect of using pip when conda can be used.

Everything might keep working if you use pip to install vs conda. However, Conda cannot manage dependencies that pip has installed - it cannot upgrade them, or remove them. More importantly, conda will install a package even if its already been installed with pip! Try this test:
conda create -n testenv python=3
conda activate testenv
pip install numpy
conda install scipy
You will see from the third command that conda will want to re-install NumPy, even though it has already been installed with pip. This can cause problems if there are C libraries whose linking is different, or something like that. In general, whenever possible, use conda to install packages into conda environments.

Related

How to install a package only within a conda environment, without affecting other environments?

I thought that this would simply be done by running pip install within the environment (after source activate). But in my case, pip install affects ALL my environments.
For example, I am trying to install an older version of torch only in env1, but if I run pip install torch==1.1.0 after source activate env1 all my environments have torch version 1.1.0.
I also tried manually running pip as described in this answer
but it didn't work.
How can I fix that?
Versions
Anaconda 3, 2019.07
Python 3.7

Installed standalone Python 3.7 after Anaconda Python 3.7, how to access old/specific pip?

I'm relatively new to Python. I installed 3.7 as part of Anaconda package, but it wasn't working with PowerBI since it wasn't able to execute a certain batch file that started the conda venv. A workaround I read about was to install a regular Python 3.7 outside of conda and use that interpreter instead.
It successfully installed, and it was added to path, and when I do pip-list in my command prompt I see only the packages for the new pip which makes sense. How do I access the old pip for my conda python where it had all the packages?
Do you mean how do you install packages in your default Python environment outside of Conda? To achieve this you'd just run pip install to install the packages fresh. If you want the list of previously install items you can use pip list.
conda activate myoldenv
pip freeze > requirements.txt
You can then open requirements.txt to see which packages that you want.
However if you want PBI to work well with Python the cleanest way in my opinion is to setup within a new conda env. The point of Conda is to have different envs for different use cases.
conda create --name VisualisationPBI python=3.7
conda activate VisualisationPBI
pip install seaborn #installs seaborn and dependencies including numpy, pandas and mpl
In PBI options set your Python home directory to "Other" then select your conda directory, probably:
C:\Users\YOURNAME.conda\envs\VisualisationPBI
Conda works with PBI, but you need to Pip install the key packages in the library, instead of conda install. As here: https://community.powerbi.com/t5/Desktop/Power-BI-Python-with-Anaconda-missing-dependency/td-p/665102

conda equivalent of pip install

If I have a directory with setup.py, in pip, I can pip install . in the directory to install the package.
What if I am using conda?
conda install . makes conda to find a package named dot.
conda packages are a different structure than standard python packaging. As a result, the official, recommended and best-practice approach is to use conda to install pip within an activated conda environment, and use that to install standard packages:
conda install pip
NOTE: You want to use conda packages whenever they're available, as they have more features within a conda environment than non-conda packages.
conda install pip will install pip within the currently activated conda environment, and will ensure that it is integrated with conda so that, for example, conda list, will include any packages installed with pip.
NOTE: Commands like conda update will ignore pip installed packages, as it only checks conda channels for available updates, so they still need to be updated using pip. See this Question/Answer discussion:
Does conda update packages from pypi installed using pip install?
NOTE: See #kalefranz comment below regarding conda 4.6 experimental handling of packages.
If you're interested in creating your own conda package(s), take a look at this question/1st answer for a great run-down:
How to install my own python module (package) via conda and watch its changes
If you simply wish to install non-conda packages, using pip is the correct, and expected, way to go.
You can use pip install from within conda environment.
Just activate your environment using:
$ conda activate myenvironment
and use pip install . to install your package in environment's directory.
EDIT: As pointed by Chris Larson in another answert, you should install pip inside the environment using
$ conda install pip
in order to register packages correctly.
If I have a whl file, I can use pip install xxx.whl to install it.
From the documentation, conda install from a local file is also available, but the file should be a tarball file, i.e. .tar.bz2 files.
conda install /package-path/package-filename.tar.bz2 works. And if I have multiple tarballs, I can tar them to get a .tar file, then conda install /packages-path/packages-filename.tar installs the packages in it.

In my anaconda's environment tensor, I have two pips . How can I uninstall the old version? my OS is windows10

There are two pips in my environment, I use the command "conda list" to list them
pip 18.0
pip 9.0.1 py35_1
I want to remove pip 9.0.1, how can I do it?
Have you tried conda uninstall pip=*version*?
You could also run conda uninstall pip (possibly conda uninstall pip*) and remove both versions, then install the latest version of pip after that.
Two versions of pip in a single conda env should not happen through the usual update processes. Either you mistakenly installed the second, or something went very wrong with anaconda. If you suspect that it is something on anaconda's end, then this is a good opportunity for some spring cleaning. Export and then remove the environment, update and clean conda, then either:
Rebuild the environment by removing anything you don't need from your exported environment file and importing this environment again. Then run another conda update --all to ensure you are on the latest version for these packages.
OR Create a fresh environment, manually go through your exported environment and install only your most-used packages. I'd recommend this one, to get a better understanding of what dependencies your projects actually need.
Addendum:
Kota Mori comments that:
Two pip's can happen if you: 1. conda istall pip, then 2. pip install pip --upgrade.
I did not consider this in my original answer. The Conda user guide does not explicitly advise against installing packages through a non-conda version of pip: Anything installed by your pip 18.0, is in the currently active conda environment.
Pip packages do not have all the features of conda packages, and we recommend first trying to install any package with conda. [...] To gain the benefits of conda integration, be sure to install pip inside the currently active conda environment, and then install packages with that instance of pip.
However, (and this is speculation) given that Anaconda aims to simplify package management for Python and R, it may be developed for the pip version delivered by conda. Delivering v10 would then be deliberate. I would personally be wary of unintended side effects and would choose to recreate my environment if I cannot cleanly uninstall v18 and return to v10, or whichever version is currently distributed through conda.

Can conda coexist with pip?

Maybe is a stupid question but I would like to install a python package that is in conda but not in pip. This is the package:
https://wrf-python.readthedocs.io/en/latest/installation.html
I don't have conda installed. My concern is that can conda coexist with pip? In other words, if I install conda and install that package, I would be able to use it with all the packages that I already have installed in pip?
thanks
You can do this by running
conda config --add create_default_packages pip
and pip will be installed in any new environment.
But, the whole point of conda is for it to work better than pip, so I would suggest using conda instead of pip at all times.

Categories

Resources