I'm trying to save my conda environment so I can send it to others to reproduce my work. Within my activated environment:
(env_name) c:\eric\ conda env export > environment.yml
This environment has dozens of packages installed (including numpy, matplotlib). When I open the resulting environment.yml file, I get only:
name: env_name
channels:
- conda-forge
- defaults
prefix: C:\Users\eric\Miniconda3\envs\env_name\envs\env_name
That is the entire file: there isn't even a line for dependencies: that shows up, which usually does show up for the packages in the env.
I am using miniconda, version 4.12.0, and have run conda update conda.
Conda issues
I found two issues at conda that have come up with this:
https://github.com/conda/conda/issues/8839
https://github.com/conda/conda/issues/10997
One solution at the first issue is to use the following command:
conda env export -p path-to-folder > environment.yml
Unfortunately this did not work for me, but it seems to have worked for many.
Comparison to related question
Note indeed the prefix value is pretty strange it typically is something like:
C:\Users\eric\.conda\envs\env_name
Frankly I am not concerned about that, unlike the related question focused on removing that prefix and the accepted answer does that bash shell commands: Anaconda export Environment file.
My question is more first-order: why aren't dependencies showing up in my yaml file?
e.g., something like the following should be appearing:
dependencies:
- pandas=1.0.3=py37h47e9c7a_0
- qt=5.9.7=vc14h73c81de_0
- pip:
- imageio==2.9.0
- scikit-image==0.17.2
But literally there are zero dependencies, and not even a dependencies argument.
It's possible the environment isn't properly activated and therefore it's not actually exporting what is wanted. Fortunately, most Conda commands provide arguments to specify an environment explicitly. Specifically, try using the --name,-n argument, like
conda env export -n env_name > env_name.yaml
Personally, I try to always use an --name,-n or --prefix,-p flag, because I find context-sensitive commands are more prone to errors (e.g., installing in incorrect environments).
Related
Here's an excerpt from my environment.yml:
name: my-project
channels:
- pytorch-nightly
- defaults
dependencies:
- pytorch=1.13.0.*
- pip:
- https://github.com/explosion/spacy-models/releases/download/nb_core_news_md-3.3.0/nb_core_news_md-3.3.0-py3-none-any.whl
prefix: ~/opt/miniconda3/envs/my-project
When I create my environment (conda env create -f environment.yml) and re-export it to environment.yml (conda env export > environment.yml), the file gets changed:
name: my-project
channels:
- pytorch-nightly
- defaults
dependencies:
- pytorch=1.13.0.dev20220614=py3.9_0
- pip:
- nb-core-news-md==3.3.0
prefix: ~/opt/miniconda3/envs/my-project
Then, when I re-create my environment the next day, Conda complains that pytorch=1.13.0.dev20220614=py3.9_0 does not exist because it was replaced by a new PyTorch Preview (Nightly) build. dev20220614=py3.9_0 is no longer available.
Conda also complains that nb-core-news-md==3.3.0 does not exist. It was installed via a URL directly to the whl. That URL was removed from the environment.yml.
How can I prevent conda env export from changing these two dependencies? I still want Conda to lock down the specifics for all other dependencies, just not for these two.
I get why PyTorch is deleting daily builds, but it's kind of disruptive for the workflow you have. What you're asking for cannot be expressed with Conda CLI commands. Instead, consider exporting the regular YAML, but then run some sed commands to replace the particular requirements prior to recreating the environment.
I exported a conda environment in this way:
conda env export > environment.yml´
Then commited and pulled the environment.yml file to the git repo.
From another computer I cloned the repo and then tried to create the conda environment:
conda env create -f environment.yml
First I got a warning:
Warning: you have pip-installed dependencies in your environment file,
but you do not list pip itself as one of your conda dependencies.
Conda may not use the correct pip to install your packages, and they
may end up in the wrong place. Please add an explicit pip dependency.
I'm adding one for you, but still nagging you
I don't know why conda export does not include pip in the environment definition.
Then I got errors like wrong/unavailable versions of packages:
es-core-news-sm==3.0.0 version not found
I just removed the version part and only left the name of the package and got it work with:
conda env update --prefix ./env --file environment.yml --prune
Here additional details:
I would like to know how can I avoid this behavior?
es-core-news-sm==3.0 does not exist on pypi, where only 3.1 and 2.3.1 are available, hence your error message.
This is of course something very specific to the environment that you have and the packages that you have installed. In your specific case, just removing the version can be a fix, but no guarantee that this will work in all cases.
As for the cause, I can only guess, but what I expect happened in your case is:
You installed es-core-news-sm==3.0 to your environment
The developers of that package created a newer version and decided to delete the old version
Exporting the environment does correctly state that it contains es-core-news-sm==3.0
Creating an environment from the .yaml from step 3 fails, because the packe is not available any longer (see 2.)
An alternative (depending on your usecase) coul;d be to use conda-pack, which can create a packed version of your environment that you can then unpack. This only works though if the OS on the source and target machine are the same
I have a conda environment setup already.
I want to delete a few packages out of it, update few and add a few new packages.
currently, I am doing it manually one after another after source activate <my_exiting_conda>.
conda update x
conda update y
conda remove z --force
conda remove w --force
conda install -c <channel> <package name>
Is there any way using which I can put all these commands in a file and just use it to do all work at once.
Also when I run the above command manually, it asks to hit Y/n for each command? how can I avoid that?
Consider switching to using YAMLs to manage your envs and refrain from using conda update/install/remove commands. When you want to make multiple changes to an env, change them in the YAML, then use:
conda env update -f environment.yaml
This command also has the optional argument --prune which will remove any packages that are not required, i.e., provides the package deletion mechanism you seek.
Note that conda env commands do not provide a transaction review step. For that reason, I would not recommend using it to manage the base env.
Starting from Existing Env
To get a working YAML from an existing env (say foo), try running something like
conda env export -n foo --from-history > foo.yaml
The --from-history argument will only include the explicit specs that you've provided to the env, so the YAML will look closer to what one might make and maintain from scratch.
Note that if there were packages installed through pip they won't appear in the --from-history version. In that case, I would still begin from this version, then export a full YAML to capture any pip specs, and add them to the simpler version.
Yes, you can pass packages in one go
conda update x y
conda remove z w --force
I would like to export a conda environment, so that I can use it on another PC. I found this:
https://docs.anaconda.com/anaconda-cloud/user-guide/tasks/work-with-environments/
And used the command that is in there, in the command promt opened via the anaconda navigator as follows: conda env export --name root -f root.yml. No feedback was given, and the root.yml file seems nowhere to be found.
After looking on stackoverflow, I found the command conda env export > root.yml. However, still no feedback is given, and the root.yml file is also missing. Running only conda env export gives a list of the name, channels, dependencies, and prefix. However, still no yml file to export.
I have the following versions:
conda version : 4.7.12
conda-build version : 3.18.8
python version : 3.7.3.final.0
Can anyone tell me what I am doing wrong?
Try using this command:
conda list --name root --export > root-env.txt
This is one of the recommended methods for saving an environment spec. List the contents in a known format that conda can reuse (the --export flag) and then write to a file using the > operator.
The exported file will be in whatever directory you are running the command from. I.e. running:
C:\Users\hello>conda list --name root --export > root-env.txt
Will save the file to
C:\Users\hello\root-env.txt
Although this is an old question & answer, I also just faced the same problem recently. I post my experience in case it helps others currently facing this issue.
When using the command:
conda env export --from-history
(or any option following conda env) I would get only a [y/N]: in the output and no response.
I found two solutions to solve the issue:
conda must itself be installed in that environment (calling it from the base environment results in the empty prompt response)
upgrading conda from 4.13.0 to 4.14.0 (in that environment) conda update conda
I am trying to install a new conda environment that will be totally separate from my other environments, so I run:
conda create --name foot35 python=3.5
Anaconda then asks for my approval to install these NEW packages:
asn1crypto: 0.22.0-py35he3634b9_1
ca-certificates: 2017.08.26-h94faf87_0
cachecontrol: 0.12.3-py35h3f82863_0
certifi: 2017.7.27.1-py35hbab57cd_0
cffi: 1.10.0-py35h4132a7f_1
chardet: 3.0.4-py35h177e1b7_1
colorama: 0.3.9-py35h32a752f_0
cryptography: 2.0.3-py35h67a4558_1
distlib: 0.2.5-py35h12c42d7_0
html5lib: 0.999999999-py35h79d4e7f_0
idna: 2.6-py35h8dcb9ae_1
lockfile: 0.12.2-py35h667c6d9_0
msgpack-python: 0.4.8-py35hdef45cb_0
openssl: 1.0.2l-vc14hcac20b0_2 [vc14]
packaging: 16.8-py35h5fb721f_1
pip: 9.0.1-py35h69293b5_3
progress: 1.3-py35ha84af61_0
pycparser: 2.18-py35h15a15da_1
pyopenssl: 17.2.0-py35hea705d1_0
pyparsing: 2.2.0-py35hcabcaab_1
pysocks: 1.6.7-py35hb30ac0d_1
python: 3.5.4-hedc2606_15
requests: 2.18.4-py35h54a615f_1
setuptools: 36.5.0-py35h21a22e4_0
six: 1.10.0-py35h06cf344_1
urllib3: 1.22-py35h8cc84eb_0
vc: 14-h2379b0c_1
vs2015_runtime: 14.0.25123-hd4c4e62_1
webencodings: 0.5.1-py35h5d527fb_1
wheel: 0.29.0-py35hdbcb6e6_1
win_inet_pton: 1.0.1-py35hbef1270_1
wincertstore: 0.2-py35hfebbdb8_0
I don't know why it suggests these specific ones. I looked up lockfile and its website says:
Note: This package is deprecated.
Here is a screenshot of my command prompt as additional information.
I am trying to do a clean install that is unrelated/independent to the root environment.
Why is conda trying to install these things and how do I fix it?
conda create will "Create a new conda environment from a list of specified packages." ( https://conda.io/docs/commands/conda-create.html )
What list??!? The .condarc file is the conda configuration file.
https://conda.io/docs/user-guide/configuration/use-condarc.html#overview
The .condarc file can change many parameters, including:
Where conda looks for packages.
If and how conda uses a proxy server.
Where conda lists known environments.
Whether to update the bash prompt with the current activated environment name.
Whether user-built packages should be uploaded to Anaconda.org.
**Default packages or features to include in new environments.**
Additionally, if you ever typed conda config, even accidentally...
The .condarc file is not included by default, but it is automatically created in your home directory the first time you run the conda config command.
A .condarc file may also be located in the root environment, in which case it overrides any in the home directory.
If you would like a single clean env then Boshika's recommendation of --no-default-packages flag for an instance though, you can check and modify the default packages for all further envs. ( https://conda.io/docs/user-guide/configuration/use-condarc.html#always-add-packages-by-default-create-default-packages )
Always add packages by default (create_default_packages)
When creating new environments, add the specified packages by default. The default packages are installed in every environment you create. You can override this option at the command prompt with the --no-default-packages flag. The default is to not include any packages.
EXAMPLE:
create_default_packages:
- pip
- ipython
- scipy=0.15.0
Lockfile may be there due to legacy requirements across all operating systems. Hopefully, you have the tools to remove it if you choose.
To avoid conda from installing all default packages you can try this
conda create --name foot35 --no-deps python=3.5
please don't loose the hope it's very weird for me also.
What you have to do just follow the steps: -
1.Download the anaconda for you system from it's official site and Install it : https://repo.continuum.io
After the Installation process, you can select your own package from there and please don't need to download anything from anywhere, it's full of packages over the internet.
3.If you want to work on python download Syder IDE its very useful for the Machine learning library.
Don't create other environment instead of root by defaults otherwise you have to duplicate all the file again, if there is any error while installing in root so close the window and again run as administration and after that its works fine.
Cause all the file in your root environment so you don't worry about the path in future and you can install and uninstall the packages : like - numpy , pandas, tensorflow and its gpu , scikit-learn etc from there eaisly.
Thank you
These packages are generally useful if you wish to pip install ... anything. Without many of them doing a pip install requests could result in errors such as these (and more)
No Module named Setuptools
pip: command not found
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available
The issue that the conda create ... exposes is that the packages it wants to pull down are variable (based on when you create the environment). If you wish to maintain the same environment for you and for those who may collaborate with you, then freezing or pinning conda create's default installed package may be necessary.
One way of doing this is creating your environment with conda env create using a conda environment YAML file such as this example:
dependencies:
- ca-certificates=2018.03.07
- certifi=2018.4.16
- libedit=3.1.20170329
- libffi=3.2.1
- ncurses=6.1
- openssl=1.0.2o
- pip=10.0.1
- python=3.6.6
- readline=7.0
- setuptools=40.0.0
- sqlite=3.24.0
- tk=8.6.7
- wheel=0.31.1
- xz=5.2.4
- zlib=1.2.11
conda env create -n <NAME_OF_ENVIRONMENT> -f <PATH_TO_CONDA_REQUIREMENTS_FILE>
(note it's conda env create not conda create)