how to pip install a package under conda virtual env - python

I need to install mpl_finance under a conda virtual environment, this package is not available via conda, only pip can install. I have tried below, does not work out, please advice.
I first set up a virtual env called cs231p under user/miniconda3/envs/cs231p.
I cd to user/miniconda3/envs/cs231p/bin, and activated the env
conda activate cs231p
Then I do: conda list to make sure pip is there:
ca-certificates 2019.1.23 0
certifi 2019.3.9 py37_0
libcxx 4.0.1 hcfea43d_1
libcxxabi 4.0.1 hcfea43d_1
libedit 3.1.20181209 hb402a30_0
libffi 3.2.1 h475c297_4
ncurses 6.1 h0a44026_1
openssl 1.1.1b h1de35cc_1
pip 19.0.3 py37_0
Then I do:
which pip
shows
/miniconda3/envs/cs231p/bin/pip
(cs231p) bin$ pip install mpl_finance
I got error: but the path of pip is not from the virtual env that I set up.
XXX/anaconda/bin/python3.5: can't open file 'install': [Errno 2] No such file or directory
python -m pip install mpl_finance
gives
requirement already satisfied:mpl_finance in
~/anaconda/lib/python3.5/site-packages (0.10.0)

Instead of pip install ... you can also use python -m pip install ....
But you run pip install and you get python3.5 can't open file "install" - it looks like your pip is not real pip but alias for python3.5.
Run python3.5 install mpl_finance and you get the same error.
Maybe you have own local script/file with name pip and when you run it then it uses this script instead of expected pip.
You can always try full path /miniconda3/envs/cs231p/bin/pip install mpl_finance.
You can also create new environment to test if it is only problem with this one environment.

activate anaconda virtual environment
conda activate <env name>
install the package using pip
python -m pip install <package>
deactivate conda virtual env
conda deactivate

Related

Trying to download ipykernel onto my virtual environment (Windows)

I am trying to install ipykernel onto my virtual venv enrioment on windows. I typed python -m pip install ipykernel but I get the following error:
ERROR: Could not build wheels for psutil, pyzmq, which is required to install pyproject.toml-based projects
I tried downgrading using the command pip install pip==21.3.1 but I did not find any luck downloading pip onto my venv afterward either. I also tried using the command python -m pip install ipykernel which also did not work.
Let me know if you have any other ideas!
Try installing from source
git clone
cd ipykernel
pip install -e ".[test]"

Force uninstall of the package pip

I'm sorry if this is a repeat question, but whenever I search force uninstall of pip I get something like a pip uninstall command. What I want is a way to uninstall the package pip (and reinstall). when I run python3 -m pip uninstall pip setuptools in a conda enviroment I get this error:
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pip'. No files were found to uninstall.
Found existing installation: setuptools 45.2.0
Not uninstalling setuptools at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'setuptools'. No files were found to uninstall.
I also get the same error in the base enviroment when I run /usr/lib/python3 -m pip uninstall pip setuptools.
However when I'm outside of a virtual enviroment (base) and I just run python3 -m pip uninstall pip setuptools, I get:
/home/cameron/anaconda3/bin/python3: No module named pip
I could just remove the file but I want to avoid if that would be problematic.
The problematic thing is I can still install things with pip in my base enviroment but I can't call python programs in my virtual enviroments anymore nor install new ones with pip (perhaps able to with conda) since it defaults to the packages installed with this pip even in a venv.
this should remove pip from your active conda environment
conda uninstall pip --force
I was finally able to remove with sudo apt-get purge python3-pip

Installing a package inside Conda using apt install

I'm trying to install opencv in my Jetson TX2. I would like to install it within my conda environment. I used the following command to do so,
sudo apt-get install python-opencv
It actually installs opencv but outside the conda so I'm not able to import it within conda. How can I have it installed within my conda?.
apt install for system-wide package install
conda install for installing package in conda environment
Make sure you are in a conda environment.
Run a conda command, instead of an apt-get command.
conda install -c conda-forge opencv
You can just install pip in the conda environment and install opencv using pip.
conda install pip
pip install opencv-python

Installing tensorflow on Anaconda

I have a linux machine to which i installed Anaconda.
I am following:
https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html
pip instaltion part.
To be more specific:
which python
gives
/home/user/anaconda2/bin/python
After which i entered:
export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
And after:
sudo pip install --upgrade $TF_BINARY_URL
However,
while trying:
python -c "import tensorflow"
I get an import error:
ImportError: No module named tensorflow
The 'sudo' makes pip install tensorflow outside the env. Try:
pip install --upgrade $TF_BINARY_URL
Just tested this on Ubuntu 14.04 w/ conda env, was able to reproduce (with sudo) and resolve issue (without sudo).
You can also check the "Using Conda" section of tensorflow.org. They list the below:
# Python 2
(tensorflow)$ pip install --ignore-installed --upgrade $TF_BINARY_URL
# Python 3
(tensorflow)$ pip3 install --ignore-installed --upgrade $TF_BINARY_URL
In anaconda, simply do:
for installation
conda install -c conda-forge tensorflow
for update/upgrade
# -f will force the current installation to upgrade
conda update -f -c conda-forge tensorflow

Pip doesn't show my installed packages

pip won't show my installed packages.
I did
brew install python
sudo -E pip install virtualenv
pip list
pip (1.5.6)
setuptools (5.4.2)
wsgiref (0.1.2)
Why isn't pip showing virtualenv?
This pip is the version installed by brew.
When I installed python, it says:
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
Looking in this directory, virtualenv is not there.
Doing an updatedb; locate virtualenv, I find it installed here:
/lib/python2.7/site-packages/
What gives? Pip installs to above location, but isn't aware of it when I do pip list!
EDIT: In response to #jordanm's comment,
sudo -E pip install virtualenv
Password:
Downloading/unpacking virtualenv
Downloading virtualenv-1.11.6-py2.py3-none-any.whl (1.6MB): 1.6MB downloaded
Installing collected packages: virtualenv
Successfully installed virtualenv
Cleaning up...
sudo -E pip install virtualenv most likely installs virtualenv to OSX provided system-wide Python installation, not Homebrew installed Python.
Try:
brew install pyenv-virtualenv
instead.

Categories