I am trying to create a new empty evironment with conda using the command:
conda create -n name python=3.6
Then I activate the environment and export it with
conda env export > environment.yml
I have noticed that the generated yml files contains a lot of pip packages that I guess are installed system wide. I am a ROS user and all the python packages installed by ROS appear there. Is there a way to ensure that those pip packages are not included in my new environment?
Thanks a lot for your help.
Make sure that you created the environment not using
conda env create -n name python=3.6
but using instead the command
conda create -n name python=3.6
Using the first command will link all packages from your base environment.
Also note that your new environment will contain several default packages (such as Python 3.6, pip, etc.) if you use the flag python=3.6 when creating the environment.
Related
I'm creating a Conda environment and want to make sure it allows anyone to run the scripts in my repository without having to install anything separately. But, I have pip installed some packages on my machine, so, if I understand correctly, some of my imports might work because I pip-installed them and not because they're installed in the Conda environment.
For example, suppose I created an environment with conda create --name my_env python=3.8.8. This shouldn't install Pandas, but if I run import pandas as pd, it works. I believe this is because I've pip-installed Pandas. My question is:
How can I test whether a script works with only packages installed in the conda environment?
You can create a yaml file just from the history of your conda installations:
conda env export --from-history --name my_env > myenv.yml
From that you create a new conda environment, which you can use to test your script with:
conda env create --name conda_only --file myenv.yml
Python has flags to ignore PYTHONPATH (-E) and default system- or user-level site-packages (-S), as well as a combined flag (-I) that does both (see python -h). Try using such flags to isolate from the system. Something like,
conda run -n my_env python -I script.py
Also, it should be clarified that pip install is only an issue like this if you are using the --user flag, which triggers a user-level installation of packages, or some alternate location (e.g., --root or --prefix flags) and have PYTHONPATH set to make those accessible.
I am about to program 2 different python projects on my computer, each of them is using a different version of a specific module (PyTorch), as well as modules from the latest anaconda.
I have already installed anaconda and found out that the solution is a virtual environment, however, I don't want to install all anaconda modules for each one of them, but use the already installed anaconda for both of them.
How do I do it?
You can use virtual environment which allows you to install specific packages (with specific version) and/or specific python version.
From the docs,
To create virutal environment called myenv
conda create -n myenv
# Create with specific python version
conda create -n myenv python=3.6
# Create with specific version of python and package
conda carete -n myenv python=3.5 pytorch=1.2
To use a virtual env, you have to activate it.
# Activating myenv
conda activate myenv
To deactivate a env, and fall back to default anaconda env,
# myenv
conda deactivate
conda activate base
# Anaconda default env is called base
To list available virtual env
conda env list
or
conda info --envs
Problem
I am trying to create a virtual environment for my deep learning project. However, after I created and activated the environment called venv using the following commands
conda create -n venv anaconda
conda activate venv
I found that many of the deep learning packages were not shipped with this virtual environment (the left panel is conda list outside the virtual env while the right panel is the one inside).
I noticed that packages not imported has "channel" property called conda-forge or pytorch
Therefore, I am wondering how could I create an virtual environment that copies all packages rather than that only have native packages. Thank you in advance!
why dont you export the results of conda list into a text file, then make a new venv using this text file:
conda list --export > requirements.txt
conda create -n new --file requirements.txt
I think you can also do this, but haven't tested:
conda create -n new --clone base
I know how to add single packages and I know that the conda create command supports adding a new environment with all anaconda packages installed.
But how can I add all anaconda packages to an existing environment?
I was able to solve the problem as following:
Create a helper env with anaconda: conda create -n env_name anaconda
Activate that env conda activate env_name
Export packages into specification file: conda list --explicit > spec-file.txt
Activate the target environment: activate target_env_name
Import that specification file: conda install --file spec-file.txt
I have anaconda3 using python 3.5. I wanted to experiment with something in python 2.7 so I opened the anaconda command prompt and ran:
conda create -n py27 python=2.7 anaconda
In retrospect that may have been overkill; I didn't need everything in anaconda. I now want to remove it. What I tried
I looked for a uninstall executable for the py27, but couldn't find one
the docs say to: conda - conda uninstall (but that returned: could not locate 'conda--'
I also tried looking in control manager (windows) to see if it was available to uninstall, but it was not
Question: How do I undo conda create -n py27 python=2.7 anaconda? That is to say, I want to go back to my original anaconda3 python 3.5 and no py27.
When you use the create command, you are not replacing your current environment, just creating a new one.
You can see a list of your environments using the following command:
conda info --envs
Then, you can activate a specific environment using (replace py27 by the name of the environment):
On windows: activate py27
On linux: source activate py27
To delete the newly created environment use the following command:
conda remove --name py27 --all
The "all" parameter will also delete any configuration and packages installed with the environment.
Edit
New environments are installed inside the envs folder of your anaconda root so after removing it you can check the folder in case there is anything left, e.g.:
C:\Anaconda3\envs\py27
More info: https://conda.io/docs/user-guide/tasks/manage-environments.html
You only have to delete the environment you do not need any longer:
$ conda env remove -n <env_name>
In your case:
$ conda env remove -n py27
more info here