Create a virtual environment by reading the Conda environment configuration file in Anaconda Navigator
Anaconda is a very useful environment for implementing Python for scientific calculations. Many people use Anaconda. However, if you keep installing and updating packages to the environment you have created, you may lose track of dependencies, and you may not be able to reproduce the environment on other computers.
To prevent this from happening, create and manage your preferences file well so that anyone can reproduce a virtual environment anywhere. In this article, we will show you how to create a virtual environment from an environment settings file using Anacnoda Navigator, a GUI rather than a CUI, so that even beginners can use it.
1. prepare environment setting file (yaml file)
The following is an example of an environment configuration file "env.yml". The file name can be arbitrary, but the extension should be "yml".
name: test-env
channels:
- defaults
- gurobi
dependencies:
- python=3.8
- gurobi
- spyder
- pandas
- openpyxl
”name" is the name of the virtual environment. Give it a name that is easy to understand, such as the purpose of using this environment.
"channels" specifies the channels from which the package will be downloaded. Most packages are fine with "defaults", but certain packages require special channels to be specified. Make sure you know where the package you want to use can be downloaded from.
”dependencies" specifies the packages you wish to install in this environment. Basically, the latest version is installed, but if you want to specify a version, add "=" after the package name to specify the version.
Keep this preference file for each programming you create. One environment per programming. If you are using Git to manage your programming, you can naturally manage them together by adding the preferences file to your Git tracking.
2. import the preferences file
①. Select "Environments".
②. Select "Import".
③. Choose "Local drive" and set up the preferences file (edit "Name" if you want to change the environment name).
④. Select "Import".
3. if you want to install a new package in your environment
It is installed using Conda, a package that is included by default in the Anaconda virtual environment.
conda install [Package-Name]
After this, do not forget to add the installed packages to the "dependencies" section of the configuration file. If you forget to do so, you will not be able to reproduce the environment on other computers.
コメント
コメントを投稿