简体   繁体   中英

is it necessary to install Requests library at Virtual Environment in python?

I am new at python, using virtual environment etc. I installed python in C drive, added PATH variable and worked from there. For learning purposes, I decided to install packages only inside my project directory. So, I created virtual environment inside my project folder by following a documentation. I have created it at my windows machine something like this way:

python -m venv my-env

After that, I activated it:

my-env\Scripts\activate.bat

After that, I have installed the Requests library (as it was in the documentation):

pip install requests

But, my question is: why need to install Requests library? Do I need to install it again if I create new project, new virtual environment inside that new project directory at future?

I installed some additional packages And I wanted to create requirements.txt. So, I wrote:

pip freeze > requirements.txt

Now, besides my required libraries for the project itself, every packages from that Requests library are in that requirements.txt file too. So, if I share my project with other user, that user will get packages from the Requests library when install via requirements.txt. Is it okay?

Sorry for lots of question. Basically, all the questions are related and contextual I think.

why need to install Requests library?

There's no need to install this library for the virtual environment to work properly.

Do I need to install it again if I create new project, new virtual environment inside that new project directory at future.

The idea of a virtual env is that: that you work in a controlled environment, created for that project. If you'll work on another project, in its own virtual env, you'll have to install it again. This is not bad at all: in each project, you might need to work with different versions of the same library, or you might even want/need to delete a project, and none of what happens in one project will affect the other, which is nice.

besides my required libraries for the project itself, every packages from that Requests library are in that requirements.txt file too.

Yes, the freeze command lists all the installed packages. That will include not only what you installed by pip install ... , but also the dependencies those packages needed. This is a reason why some people suggest to write the requirements file by hand: that way it's clearer what external resources are directly needed, as opposed to each sub-dependency, which, as you might have seen, becomes a little clumsy to understand.

if I share my project with other user, that user will get packages from the Requests library when install via requirements.txt. Is it okay?

It's ok in the sense that those packages will get installed either way. They are explicitly listed, but if they weren't they'd also be downloaded and installed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM