본문 바로가기
DataScience/참고자료

Exporting Python Virtual Environment Library

by 올커 2023. 8. 13.

When developing with Python, there are cases where you need to install libraries as you switch between virtual environments.

 

In my case, I sometimes need to manage packages using both pip and conda.

 

When changing virtual environments, you can save the package list from the previous environment (or the environment you want to replicate) as a text file and then load it into the new virtual environment for installation.

 

*Sometimes, when cloning code from GitHub, there might be a "requirements.txt" file containing the list of packages that need to be installed.


1. Using pip

When using pip, you can save the package list from the previous virtual environment as follows [1) Export], and then load the package list into the new virtual environment as follows [2) Import].

 1.1) Save pip Package List (Export):

pip freeze > requirements.txt

 1.2) Load pip Package List (Import):

pip install -r requirements.txt

 

2. Using conda:

Similarly, when using conda, you can save the package list from the previous virtual environment as follows [1) Export], and then load the package list into the new virtual environment as follows [2) Import].

 2.1) Save conda Package List (Export):

conda list --export > requirements.txt

 2.2) Load conda Package List (Import):

conda install --file requirements.txt

 

※Note: Sometimes the text file containing the package list might have a different name (e.g., "packagelist.txt"). So, when cloning code from GitHub or other sources, make sure to verify the filename beforehand.

 

 

반응형

댓글