Python Forum
Do I need to make a virtual environment?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do I need to make a virtual environment?
#1
I run Ubuntu 18.04

I read I can create a "virtual environment" for Python 3 with:

Quote:python3 -m venv /path/to/new/virtual/environment

I only do simple things.

Do I need to run Python in a virtual environment?

My friend uses Windows, poor guy. Can he run Python in a virtual environment in Windows??
Reply
#2
You don't necessarily need a virtual environment, no. If you think you might want different versions of the same library for different projects, say, then I'd consider it. Of course you can create virtual environments on Windows.
Reply
#3
(Sep-19-2020, 08:43 AM)Pedroski55 Wrote: I only do simple things.

Do I need to run Python in a virtual environment?
No,but it can make a lot sense to use in some projects.
(Sep-19-2020, 08:43 AM)Pedroski55 Wrote: My friend uses Windows, poor guy. Can he run Python in a virtual environment in Windows??
Let's try Wink
# Make
C:\code>python -m venv my_env

# Cd in
C:\code>cd my_env

# Acivate 
C:\code\my_env>C:\code\my_env\Scripts\activate

# Test pip
(my_env) C:\code\my_env>pip -V
pip 19.2.3 from c:\code\my_env\lib\site-packages\pip (python 3.8)

# Install
(my_env) C:\code\my_env>pip install requests
Collecting requests .....
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0
 urllib3-1.25.10

(my_env) C:\code\my_env>pip list
Package    Version
---------- ---------
certifi    2020.6.20
chardet    3.0.4
idna       2.10
pip        19.2.3
requests   2.24.0
setuptools 41.2.0
urllib3    1.25.10

(my_env) C:\code\my_env> 
The main purpose of Python virtual environments is to create an isolated environment for Python projects.
This means that each project can have its own dependencies,regardless of what dependencies OS Python has or other project has.
As a example when doing web-development it make a lot of sense to use virtual environment,as one day may need to move code and dependencies to a server.
Reply
#4
You should also always use a requirements.txt file to declare the dependencies and their versions.
Reply
#5
I would put it off until you are comfortable using Python. Virtual environments caused me much confusion when I was first starting. I would install a package on my computer and get an error when I import the package in my program. Now that I am a bit more savvy, I see the benefit virtual environments provide.
Reply
#6
if you need to ask the answer is probably no
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 214 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Installing python packages in a virtual environment Led_Zeppelin 1 757 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Problem with virtual environment standenman 2 1,003 Feb-23-2023, 07:09 PM
Last Post: standenman
Question Virtual Environment (using VS Code) Ashcora 4 13,559 Feb-15-2023, 07:17 PM
Last Post: snippsat
  How do I link the virtual environment of that project to the 3.9.2 version of python? Bryant11 1 1,366 Feb-26-2022, 11:15 AM
Last Post: Larz60+
  Project structure with a virtual environment gdbengo 1 1,424 Jan-26-2022, 03:22 PM
Last Post: snippsat
  Virtual environment path? Led_Zeppelin 1 2,295 Jul-22-2021, 01:40 PM
Last Post: snippsat
  virtual environment heye 4 2,433 Jul-04-2021, 06:47 AM
Last Post: ndc85430
  import statement in a virtual environment leodavinci1990 1 2,341 Mar-04-2021, 12:57 AM
Last Post: snippsat
  Virtual environment and upgrading python 3.5 to 3.9 NeilUK 4 12,102 Jan-24-2021, 01:02 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020