简体   繁体   中英

Is pyenv or virtualenv essential for Django?

For the first time, I made an environment for Django with virtualbox and vagrant (CentOS 7).

But every tutorial I saw says I need to use pyenv or virtualenv. I think they are used to make a virtual environment for Django. But I don't know why I need to use pyenv or virtualenv. (For example, Cakephp3 doesn't need packages like pyenv or virtualenv.)

And I was using virtualbox and vagrant, which are already virtual environment, so I think I was making virtual environment inside another virtual environment. I am not sure if this is meaningful. Maybe pyenv and virtualenv are not necessary if I am using virtual environment like virtualbox or vmware?

Are they essential for Django? When I deploy Django in actual server, do I still need to use pyenv or virtualenv?

It is not essential but it is recommended to work in a virtual environment when you start working on Django projects.

Importance of the virtual environment.

  • A virtual environment is a way for you to have multiple versions of python on your machine without them clashing with each other, each version can be considered as a development environment and you can have different versions of python libraries and modules all isolated from one another.

  • In a most simple way, a virtual environment provides you a development environment independent of the host operating system. You can install and use the necessary softwares in the /bin folder of the virtualenv, instead of using the software installed on the host machine.

  • Many a time different projects need different versions of the same package and keeping every projects in seperate virtual environements helps a lot.

It is strongly recommended to set up separate virtualenv for each project. Once you are used to it, it will seem fairly trivial and highly useful for development, removing a lot of future headaches.

No, it's not essential to use virtualenv for Django but it's recommended because it isolates the multiple versions of python or libraries you are using for your projects on your system. If you are not using virtualenv then that library will be the part of your python home directory.

For Example: If you are using version 1 of some library for one project and later on in other projects you have to use or if it's the requirement to use version 2 of that library then using specific virtualenv (if you are working on multiple projects simultaneously) for that project enables you to use multiple libraries without any problem.

VirtualBox isolates your development operating system from your normal operating system. Virtualenv isolates your project's Python packages from the system Python packages.

Many Linux distributions install Python packages as dependencies for other software into the system-wide site-packages directory. Python doesn't have a way to version packages with the same name, so you will run into problems when your project depends on package==10.0.0 but your distribution already installed package==0.0.2 that you cannot upgrade without breaking something.

Virtual environments are extremely lightweight. They're really just a new entry in your PATH environment variable and some configuration changes to make Python look only in a specific place for packages.

There's no real downside to using a virtualenv beyond typing one extra command to activate it.

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