Re-creating a Development Environment
Now I want to re-create exactly this development environment in another folder. You can think of this as the steps your friend would do or what you would do if you want to continue working on your project on another computer. First, create a new folder. The one before was creatively named
project, so let’s name this one
same_project. You type
same_project, and then hit Enter.
So far, there are no packages installed in this virtual environment, but let’s check that with
pip list. All right, so that means when I type
python3 -m rich, I get an error because this package is not installed yet.
Next, I want to copy the requirements file from the former project folder into the current one. For this, you can use the
cp command. You type
cp ../project/requirements.txt and then a space and then
./requirements.txt With a command like this, you have to think from the perspective of your current directory you are in. The
.. is an alias for the parent directory, and there you find the project folder of the requirements file.
That’s the item you want to copy. The second part of the command is the target path, which is
. stands for the current directory, and
requirements.txt is the filename. When you press Enter, you copy the requirements file from the folder
project/ into your current directory.
Let’s check it out if it worked by typing
ls. Okay, cool, you see your
venv folder and the requirements file. But having the requirements file in your project directory and an activated virtual environment is not enough.
You also need to install the requirements. For this, you run
python3 -m pip
install—that’s a command you already know—and then a space
requirements.txt And this installs exactly the packages with exactly the versions you froze in the other project folder because they are all saved in the
Become a Member to join the conversation.