Install python packages to correct anaconda environment - python

I've setup anaconda and created a python 3.3 environment. Now I wanted to install some package (dataset). The install instructions ask to clone the git repo and run
python setup.py install
but now the packages are not installed to the environments site-packages folder but to a different anaconda location.
What are the normal steps to solve that problem? Newbie-compatible solutions are preferred. The OS is MacOSX, just is case, it is relevant.

It looks like conda automatically adds pip to your conda environment, so after you source your conda environment, i.e.:
source activate ~/anaconda/envs/dataset
you should be able to install it like this:
git clone git://github.com/pudo/dataset.git
pip install ./dataset
EDIT
Here are the exact steps I took:
$ conda create -p ~/anaconda/envs/py33 python=3.3 anaconda pip
$ source activate ~/anaconda/envs/py33
$ which pip
~/anaconda/envs/py33/bin/pip
$ pip install ./dataset/

Related

Install pandas in debian10 on a different python version

I have a device with python3.7 preinstalled, in which i have installed also python3.9. I managed to change the version I am using of python3 and now the command "python3" followed by the .py file runs with python3.9.
The problem is I tried installing pandas with pip3 but it does not work (it didn't work even in the preinstalled python3.7), so I found that in debian you can install package, for example in this case pandas, using "sudo apt-get install python3-pandas" but this command keeps installing pandas in python3.7 and not in python3.9 even if now "python3" refers to python3.9.
Has anyone ever encountered this problem and has a solution?
python3.9 -m pip install pandas
Venv
You could use a virtual environment (venv) for installing dependencies.
This venv could be project specific or global.
Run python3 -m venv .venv in your project folder to create a .venv folder, which holds the venv configuration.
Run source .venv/bin/activate to activate the venv. This will link pip3 from your python 3.9 version to the pip command.
Now you can do pip install pandas to install the pandas dependency into the venv.
Conda
Another solution would be to use Anaconda or Miniconda
https://pandas.pydata.org/pandas-docs/stable/getting_started/install.html
conda create -n name_of_my_env python
This will create a minimal environment with only Python installed in
it.
To put your self inside this environment run:
source activate name_of_my_env
On Windows the command is:
activate name_of_my_env
The final step required is to install pandas. This can be done with
the following command:
conda install pandas

Packages installed in my virtual environment arent found unless I install them using cmd prompt in windows

I am currently working on a python project using Visual Studio Code and Conda. When I try to install a package in the virtual environment it does not work (details and steps below). But if I use my computers command prompt and install that way, it does work in the virtual environment.
My steps are as follows:
I created a virtual environment as so:
conda create -n envname
Activated the environment:
conda activate envname
Tried to install a package (i tried to use conda install but package wasnt found):
pip install packagename
Then write it into my code like so:
import packagename
Which throws me this error:
ModuleNotFoundError: No module named 'packagename'
I did try the solution from this page and tried installing the package this way:
C:\Users\myname\anaconda3\envs\envname\Scripts\pip install packagename
but it returns this:
Requirement already satisfied: packagename in c:\users\name\anaconda3\envs\envname\lib\site-packages
when i type:
conda list
The package I installed is included, as well as pip. However, the package I installed shows the version # in one column, then only "pypi_0 pypi" in the last column. not sure if that means something is wrong or not.
packagename 3.41 pypi_0 pypi
As mentioned, if I type this in my computers command prompt (separate from VSC and my virtual environment):
pip install packagename
My virtual environment will pick it up as being installed.
I feel all mixed up lol, like some path somewhere isnt right but I cant figure out what
Any ideas?
No Need to explicitly activate the venv
Try using following commands.
Step 1: Create virtual env
python -m venv envname
Step 2: Switch to this newly created virtual env
Windows
.\envname\Scripts\activate
Unix
source envname/bin/activate
Step 3: install packages in the virtual env directory
pip install <packagename>

Wrong pip version for anaconda's environments. What should I do to correct the pip version when activate a env using `conda activate`?

I have 4 envs in my anaconda as listed below.
>>> conda info --envs
base /home/gph/anaconda3
py36_torch0.4 * /home/gph/anaconda3/envs/py36_torch0.4
py37_torch1.1 /home/gph/anaconda3/envs/py37_torch1.1
python3.6 /home/gph/anaconda3/envs/python3.6
In both py36_torch0.4 and py37_torch1.1, I did some test.
>>>(py36_torch0.4) gph#gph-1050Ti:~ $ whereis pip
pip: /home/gph/.local/bin/pip3.5
/home/gph/.local/bin/pip
/home/gph/anaconda3/envs/py36_torch0.4/bin/pip3.6
/home/gph/anaconda3/envs/py36_torch0.4/bin/pip
(py36_torch0.4) gph#gph-1050Ti:~ $ pip -V
pip 19.1.1 from /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5)
(py37_torch1.1) gph#gph-1050Ti:~ $ whereis pip
pip: /home/gph/.local/bin/pip3.5
/home/gph/.local/bin/pip
/home/gph/anaconda3/envs/py37_torch1.1/bin/pip
(py37_torch1.1) gph#gph-1050Ti:~ $ pip -V
pip 19.1.1 from /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5)
We can see that for each env_name we have envs/env_name/bin/pip, but the output of pip -V is always /home/gph/.local/lib/python3.5/site-packages/pip (python 3.5).
What is wrong? What should I do to make the pip version right when activate a specific env?
I have tried unset PYTHONPATH as told in this question: Wrong pip in conda env. But it is no use.
Use pip as a module called by the Python interpreter of your env.
python -m pip install some_package where python is the one active on your env, for example /home/gph/anaconda3/envs/python3.6/bin/python.
You've installed pip outside of the conda environments, directly into your home directory. This takes precedence over everything that's installed in conda.
If you want to benefit from isolation of conda environments, you cannot install packages on the user level. This will get rid of all of them (but maybe also some more):
rm -rf /home/gph/.local
You might want to have a look at what else is installed in /home/gph/.local before actually removing it.

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.

install pip3 for conda

Python2.6 was installed by default in my old centos server. Now I want to create a Python3 environment to install python3 specific module by conda
conda create -n py3 python=3.5.3
source activate py3
After activate the py3, I try to install hovercraft by pip3 install hovercraft, the shell tells "command not found: pip3". At first I thought pip3 was installed with Python3, but the result was not the case.
So I think I can install it manually. The package gzip file was downloaded from python package index, and install by conda install --file hovercraft-2.3.tar.gz. But it doesn't work.
Now I have two problems:
how to install pip3 for virtual-env create by conda?
Is it possible to install python package index downloaded package locally in conda?
pip3 and pip would make a difference only when you are not using any environment managers like virualenv (or) conda. Now as you are creating a conda environment which has python==3.x, pip would be equivalent to pip3.

Categories

Resources