I had a large python 2.7 project which require tensorflow. But I can not pip install it when I have installed Anaconda with python3.5.
pip install tensorflow
Given error:
Requirement already satisfied: tensorflow in c:\users\victo\anaconda3\lib\site-packages (1.14.0)
s\victo\anaconda3\lib\site-packages (from tensorboard<1.15.0,>=1.14.0->tensorflow) (3.1.1)
Collecting setuptools>=41.0.0 (from tensorboard<1.15.0,>=1.14.0->tensorflow)
..
Using cached https://files.pythonhosted.org/packages/b2/86/095d2f7829badc207c893dd4ac767e871f6cd547145df797ea26baea4e2e/setuptools-41.2.0-py2.py3-none-any.whl
Found existing installation: setuptools 27.2.0
ERROR: Cannot remove entries from nonexistent file c:\users\victo\anaconda3\lib\site-packages\easy-install.pth
I used to have both installations. Just install it in another folder, and run the anaconda version you need according to the project.
You should create different environments for different projects, which is a very basic function included in conda. conda is both a package manager and a environment manager.
What's a virtual environment
venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.
Examples
# create an virtual environment named py2 with Python 2.7 installed
conda create -n py2 python=2.7
# another env named py3 with Python 3.7
conda create -n py3 python=3.7
# activate an env and install package into this very env
conda activate py3
# install packages with pip, or conda
pip install tensorflow
# or
conda install tensorflow
# exit the env
conda deactivate
Tips: After an env is activated, you can use pip or conda to install packages into it. But never use both of them within a virtual environment.
Extended Reading
get started with conda
Using Pip in a Conda Environment
Related
I am using conda as the Python3 package management tool, sometimes the conda repo did not contains some Python package. So I have to install it using pip, first I found the anaconda environment folder, the next step switch to the anaconda environment folder:
cd /usr/local/anaconda3/envs/pydolphin
then using this command to install package:
./bin/pip install musicbrainzngs
is there any short way to do this? is it possible to install it the PyCharm IDE the simple way? the PyCharm IDE using conda install by default.
First activate your conda environment:
conda activate <env>
This will switch to the version of pip installed in this environment. Then you can install using pip as per normal which will install it into your conda environment:
pip install musicbrainzngs
I'm currently trying to build a conda virtual environment for a project. However some packages are still not possible to install with the pip and conda commands (such as pyqt5 or liblsl for instance), but these are necessary for the project.
I tried to install these packages using the brew install command, while being in the virtual environment, but the packages do not appear in the conda virtual environment.
So, do you know if it is possible to install packages with the brew command and include it in the virtual environment ?
I was trying to install pycryptodome, python-jose-cryptodome using pip within anaocnda3 environment.
I got this error:
ERROR: Failed building wheel for pycryptodome
I have tried many versions many solutions(latest versions, specified version, with python 3.8 or 3.7, using requirements text without cache and even alone installation) but nothing worked for me :(. Any solution?
While using pip in an anaconda environment is allowed and fine, issues may arise when using pip and conda together, this was clearly mentioned in the conda docs.
One of the best practices when installing packages in an anaconda environment is to use conda for search and install before using pip.
So instead of directly using pip, try to :
Search for pycryptodome in anaconda packages repo
conda search pycryptodome
pycryptodome is available in anaconda repo .
The next step is to install pycryptodome :
conda install -c anaconda pycryptodome
or if you want to use conda-foge channel :
conda install -c conda-forge pycryptodome
this should get pycryptodome installed into your env
To use a requirements.txt file with conda :
conda install --yes --file requirements.txt
Summary : Best Practices Checklist When Using Pip in a Conda Environment
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” 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 .
you can read more about this topic here on anaconda website, and on conda docs
I'm working on a (python) project where the choice was to create a virtual environment using virtualenv. However, one of the project dependencies can't be installed through pip on macOS due to this bug: https://github.com/streamlit/streamlit/issues/283
The workaround is to conda install one of the dependencies to bypass the gcc compiler.
How do you conda install something in a virtual environment not created with conda?
I think the easiest approach would be to create a conda env by it's own.
1) Create a requirement.txt file by doing pip freeze > requirements.txt inside your virtualenv environment
2) Create conda env: conda create --name myenv
3) Activate your environment: source activate myenv
4) Install your dependencies: conda install --file requirements.txt
5) Install missing dependecy: conda install YOUR_MISSING_DEPENDENCY
In the accepted answer (upvoted) you can also change point 1) to use conda-installed packages (compatible with subsequent conda install, and excluding pip-installed packages that would be unavailable in conda channels, identified by "pypi" in their extended version names that only conda displays):
conda list --export | grep -v pypi > requirements.txt
And if you still want to use pip, the correct syntax that gets you packages versions list in a format compatible with pip install is now:
pip list --format=freeze > requirements.txt
I have a python project that uses virtualenv. I have installed various packages using pip install <package-name> with the virtual environment activated. I now want to generate a list of these packages. I am using the command pip freeze >requirements.txt (again with the virtual environment activated) however when I open the file all I see is:
virtualenv==15.1.0
I don't see any of the other packages I have used. What am I doing wrong here?