I wanted to create a conda environment to work on a Django Web App.
I checked if the environment had existed before:
conda activate django_movie_app
Could not find conda environment: django_movie_app
You can list all discoverable environments with `conda info --envs`.
Then I created my environment using:
conda create --name django_movie_app
Collecting package metadata (current_repodata.json): done
Solving environment: done
However after I activated the environment using
`conda activate django_movie_app`
I checked pip freeze and all system packages were installed
pip freeze
alabaster==0.7.12
anaconda-client==1.7.2
anaconda-navigator==1.9.12
anaconda-project==0.8.3
argh==0.26.2
asgiref==3.2.4
asn1crypto==1.3.0
astroid==2.3.3
astropy==4.0.1.post1
atomicwrites==1.4.0
attrs==19.3.0
autopep8==1.5
Babel==2.8.0
backcall==0.1.0
backports.functools-lru-cache==1.6.1
backports.shutil-get-terminal-size==1.0.0
backports.tempfile==1.0
backports.weakref==1.0.post1
bcrypt==3.1.7
beautifulsoup4==4.9.0
bitarray==1.2.1
bkcharts==0.2
bleach==3.1.4
bokeh==1.4.0
boto==2.49.0
Bottleneck==1.3.2 etc
Running conda info returned the environment was active:
conda info
active environment : django_movie_app
I have tried reinstalling the environments after deleting them from the explorer (They were not available afterwards --> See above) and I still had the same problem afterwards.
I have created normal environments before where this was not a problem. However, now conda keeps installing all packages and some older versions cannot be uninstalled using pip uninstall.
With the commands you listed above, you haven't actually installed anything to the django_movie_app environment yet, so when you call pip, your shell is finding some other version of pip that happens to exist on your PATH -- not one from the django_movie_app environment. (It looks like your conda base environment is still on your PATH somewhere. That's not necessarily a problem, as long as django_movie_app/bin.)
Does everything work as expected if you try the following commands?
conda create -n django_movie_app
conda activate django_movie_app
conda install python=3.7
pip freeze
BTW, the conda command to list your current environment's installed packages is:
conda list
...which gives a little more info than pip freeze.
conda create --name py37 python=3.7
conda activate py37
Check the Conda Cheat sheet for more understanding and to see multiple commands with their description.
Related
Conda says the package is already installed and will not install it again, but when I list the packages in the environment, there are no packages installed.
When I try to import the package in a notebook file, it fails.
Running a terminal shell launched from JupyterLab:
Use pip to uninstall bashplotlib - that works
Use Conda to activate an environment -- That works
Use Conda to install bashplotlib -- It fails because it's already supposedly installed
Use Conda to print the packages installed in the Conda environment -- There are none listed
PS C:\Users\nicomp> pip uninstall bashplotlib
Uninstalling bashplotlib-0.6.5:
Would remove:
c:\users\nicomp\anaconda3\lib\site-packages\bashplotlib-0.6.5-py2.7.egg-info
c:\users\nicomp\anaconda3\lib\site-packages\bashplotlib\*
c:\users\nicomp\anaconda3\scripts\hist-script.py
c:\users\nicomp\anaconda3\scripts\scatter-script.py
c:\users\nicomp\anaconda3\scripts\scatter.exe
Proceed (Y/n)? y
Successfully uninstalled bashplotlib-0.6.5
PS C:\Users\nicomp> conda activate fooEnvironment
PS C:\Users\nicomp> conda info --envs
# conda environments:
#
base * C:\Users\nicomp\anaconda3
bashplotlibEnvironment C:\Users\nicomp\anaconda3\envs\bashplotlibEnvironment
condaTestEnvironment C:\Users\nicomp\anaconda3\envs\condaTestEnvironment
fooEnvironment C:\Users\nicomp\anaconda3\envs\fooEnvironment
jupyterlab-debugger C:\Users\nicomp\anaconda3\envs\jupyterlab-debugger
microservices C:\Users\nicomp\anaconda3\envs\microservices
ml C:\Users\nicomp\anaconda3\envs\ml
someEnvironment C:\Users\nicomp\anaconda3\envs\someEnvironment
zzz C:\Users\nicomp\anaconda3\envs\zzz
PS C:\Users\nicomp> conda install -c conda-forge bashplotlib
Collecting package metadata (current_repodata.json): done
Solving environment: done
# All requested packages already installed.
PS C:\Users\nicomp> conda list -n fooEnvironment
# packages in environment at C:\Users\nicomp\anaconda3\envs\fooEnvironment:
#
# Name Version Build Channel
PS C:\Users\nicomp>
Activation Failing
From the conda info --envs output, it indicates that the conda activate command is not working, since the output shows that base is still activated (that's what "*" indicates). That is, despite the efforts, the package is getting installed in base.
Specifying Target Environment
I can't answer why the environment activation is broken (this can be specific to PowerShell or the Jupyter terminal - try searching), but I can at least recommend a more robust installation command. Rather than relying on environment activation, most Conda commands support specification of the target environment using the --name,-n or --prefix,-p flags. In this case,
conda install -n fooEnvironment -c conda-forge bashplotlib
would work no matter what environment happens to be activated.
I'd encourage this as a good habit to adopt because it makes the command less context-sensitive.
I'm trying to set a conda environment using a requirements.txt file that a coworker shared with me. My coworker uses Python in a Mac without Anaconda, and I'm using it in a Windows machine with Anaconda. The file requirements.txt was generated with the command pip freeze and looks like this:
absl-py==0.7.1
affine==2.3.0
agate==1.6.0
agate-dbf==0.2.0
agate-excel==0.2.1
agate-sql==0.5.2
...
After checking the answer of this question, I tried the following in the Anaconda terminal:
conda create --name my-env-name --file requirements.txt
Which fails with the following error message:
PackagesNotFoundError: The following packages are not available from current channels:
- appscript==1.0.1
- style==1.1.0
- senticnet==1.3
- scikits.optimization==0.3
...
My understanding is that this happens because those packages are not available in the Anaconda package installation channels, and that they should be installed instead via pip with my conda environment activated, using pip install -r requirements.txt
The problem is that this list of packages is very long, and I would like to avoid having to manually check and separating which packages are included in Anaconda channels and which should be installed via pip. Then, is there a way to tell Anaconda to create an environment by automatically recognizing the packages included in its channels, installing them, and then installing the rest using pip?
Using requirements.txt with conda
There's no problem at all using a requirements.txt file when creating a conda environment.
In fact, you can also set additional channels at creation time:
conda create --name my-env-name --file requirements.txt --channel <NAME_OF_CHANNEL>
for example, in the case of the first package you mention, you can install it from anaconda channel. So you could run:
conda create --name my-env-name --file requirements.txt --channel default --channel anaconda
Why using default channel first? Well, just to give preference to the default one (the priority of channels is specified by the order they are listed: higher priority from left to right).
When at least some of the packages are not available using conda
Well, when no conda channel can provide any of your required packages, there are several alternatives:
Install through conda those packages available in any of its channels.
Install through pip the rest.
Create a conda environment.yml file:
conda env export > environment.yml
When you need to recreate this environment, then you can do:
conda env create --name my-env-name --file environment.yml
and it will install the packages using conda, will install pip, and then will install those packages only available with the latter one.
This approach has good and bad properties:
one of the good properties is that it separates those packages installed through conda from those installed using pip.
one of the bad properties is that it's only useful for conda, but not for pip alone.
I want to create a fresh conda environment called new-gooey_env.
conda create --name new_gooey_env python=3.7
I get a notification that the following packages will be insatlled:
ca-certificates pkgs/main/win-64::ca-certificates-2020.6.24-0
certifi pkgs/main/win-64::certifi-2020.6.20-py37_0
openssl pkgs/main/win-64::openssl-1.1.1g-he774522_1
pip pkgs/main/win-64::pip-20.2.2-py37_0
python pkgs/main/win-64::python-3.7.7-h81c818b_4
setuptools pkgs/main/win-64::setuptools-49.4.0-py37_0
sqlite pkgs/main/win-64::sqlite-3.32.3-h2a8f88b_0
vc pkgs/main/win-64::vc-14.1-h0510ff6_4
vs2015_runtime pkgs/main/win-64::vs2015_runtime-14.16.27012-hf0eaf9b_3
wheel pkgs/main/win-64::wheel-0.34.2-py37_0
wincertstore pkgs/main/win-64::wincertstore-0.2-py37_0
zlib pkgs/main/win-64::zlib-1.2.11-h62dcd97_4
That's great. I install them and activate my new environment.
conda activate new_gooey_env
Now when I type pip freeze, I can see that basically every package on my computer has been installed into this new environment.
The output of pip freeeze in my new environment is about 100 packages.
How can I create a new environment with just the bare minimum packages?
I have already googled this problem and followed the instructions here, which doesn't work hence the question.
Note when I type conda list I only get the list of packages above.
So is pip freeze command correct? Is there also 100 packages in my new environment?
edit: On Windows.
Use pip freeze -l .
The l stands for local .
pip freeze otherwise acts on all your environments as your virtualenv has global access. That is my best guess.
And no , your new environment doesn't have 100's of packages!
I use pip install packages in a conda environment.
pip install pygame
Requirement already satisfied: pygame in ./anaconda3/lib/python3.6/site-packages (1.9.4)
where the current directory is /Users/aptx4869. However, when I type conda list, there is nothing in the current environment. What's wrong with it? Here's the directory where the environment is at
/Users/aptx4869/anaconda3/envs/rl
Update
I delete the pygame in the root environment and run pip install pygame in the rl conda environment, I receive another message. But pygame still doesn't show in conda list
pip install pygame
Collecting pygame
Using cached https://files.pythonhosted.org/packages/bc/19/57bf1e9c72be4f7afc1add56cc717b7f7fe8ef1b6b5fb58f031a06401d0f/pygame-1.9.4-cp36-cp36m-macosx_10_11_intel.whl
Installing collected packages: pygame
Successfully installed pygame-1.9.4
(rl)
Notice (rl) in the end, this pip command still installs pygame in the root environment
The reason is simply because I didn't install python and pip in the dl environment, and conda implicitly uses python and pip in the root environment as I command pip install ...
I guess that you installed the pygame package into the root environment when you run pip install pygame the first time. So make sure that you have activated the environment into which you want to install packages and then use pip to install the packages. Doing this, you should see the packages in the list of conda list command. Also, you must run the conda list command in the same environment where you run pip install.
After facing the same problem, here is the solution that worked for me:
From a separate terminal (not VSCode integrated terminal), with my virtual environment active:
python -m pip install pygame
It is important not simply call pip (or pip3) directly, and it apparently mattered to not do it from VSCode integrated terminal.
I've run into this a few times with different packages, and 9 times out of 10 it's an issue wit managing multiple conda environments.
You can have multiple conda environments active at the same time. If you activate one environment from another environment, it doesn't necessarily close the first environment. So, say that you create myenv:
(base)$ conda create myenv
(base)$ conda activate myenv
(myenv)$
You work in that environment for a bit, run into some problems, and then realize that it's easier to start another environment from scratch. If you do
(myenv)$ conda create myenv2
(myenv)$ conda activate myenv2
(myenv2)$
You have activated myenv2. However, you haven't explicitly closed myenv. You can see this when you deactivate myenv2
(myenv2)$ conda deactivate
(myenv)$
I have't researched this behavior too deeply, but I know that it can create issues with pip installs within conda. Try deactivating your conda environments to base and then activating only the environment of interest. It fixed the problem for me, at least.
I'm trying to downgrade python version of anaconda via conda install python=3.3, but have following error:
~/anaconda3/bin$ ./conda install python=3.3
Fetching package metadata .........
Solving package specifications: .
UnsatisfiableError: The following specifications were found to be in conflict:
- gevent -> python 2.6*
- python 3.3*
Use "conda info <package>" to see the dependencies for each package.
How to resolve conflicts with the packages?
If you want to set specific version, use it like this:
WARNING: This command will overwrite the default python version system-wise
conda install python=3.6
To create environment with a specific version, you can do:
conda create -n $PYTHON36_ENV_NAME python=3.6 anaconda # set custom env name
The anaconda at the end allows the env to use all anaconda packages
For more information refere to Anaconda documentation
There are two ways to downgrade python in anaconda.
1. Downgrade python in the active environment
(This can lead to conflicts with installed packages for higher python versions)
conda activate nameOfYourEnvironment
conda install python=3.3
2. Create a new environment
(This is a more safer way, but you need to install all necessary packages again)
conda activate base
conda create --name env_name python=3.3
Hint: Use conda list before creating a new environment to get the names of all installed packages in the actual environment.
If you want to check your installed environments do:
conda env list
If you got problems in installing, make sure to run the shell as administrator (always recommended).
You can make environments with other versions of Python using this command:
conda create --name py33 python=3.3
source activate py33
Very firstly check the current version using command python --version. Then on anaconda prompt type the command conda search python which will list all the python versions available till date. Then from that list select your version and type conda install python=3.5.2 or any of your choice