- Before installing anything related to the VIRTUALENV, check if you already have this: z__ENV_PATH_issue, if you have it, you can continue, but if not, just go the link and follow the steps.
-
virtualenv is a third-party tool that allows more flexibility in specifying Python versions and has different default behaviors compared to
python -m venv
. -
The
bin/
directory withinenv/
includes β activation scripts (activate, activate.bat for Windows) and other necessary files for managing the virtual environment.
python -m venv
is part of Python's standard library (venv module), while virtualenv is a third-party tool.
Activation Scripts: virtualenv typically provides more comprehensive activation scripts (activate, activate.bat) within the bin/
directory, making it easier to activate the virtual environment.
Python Version: virtualenv β allows specifying the Python interpreter version explicitly (-p python3), whereas python -m venv uses the default Python interpreter in your system's PATH.
Preferred Tool: If you need more control over Python versions or desire a more consistent activation experience across different platforms, virtualenv with explicit Python version (-p) is often preferred.
Standard Library vs. Third-Party: Both python -m venv and virtualenv are widely used for creating virtual environments. Your choice may depend on specific project requirements or personal preference.
-
vistualenv works on the ubuntu terminal.
-
ubuntu terminal: when i type the
~$ virtualenv --version
command, i get this:
// output
virtualenv 20.26.3 from /home/mycomputer/.local/lib/python3.8/site-packages/virtualenv/__init__.py
- BUT when i try the same command
~$ virtualenv --version
in my visual studio , on that specific projectLESSON_17_Virtual_Environment_and_pip
, i get this:
virtualenv: command not found
It seems like there might be an issue with the environment variables or PATH configuration in your Visual Studio terminal, which is causing the virtualenv command not to be found.
- First check if you have any output after you type this
echo $PATH
in your ubuntu terminal:
// type this:
echo $PATH
// OUTPUT
/usr/local/bin:/usr/bin:/bin:/home/mycomputer/.local/bin:/snap/bin
- Based on the output of echo $PATH, it appears that /home/dci-st119/.local/bin is already included in your PATH variable. This is where virtualenv is installed according to your previous messages.
- πΈ Verify Visual Studio Terminal Shell
- Check which shell Visual Studio's integrated terminal is using and ensure it matches your expectations for running virtualenv commands.
// type this in your VS terminal
echo $SHELL
//
// β Output Interpretation:
// This command will display the shell currently active in your terminal session.
output:
/bin/bash, /usr/bin/zsh, /usr/bin/powershell, etc.
- πΈ Restart Visual Studio
- Restart Visual Studio to clear any temporary configuration issues that might be affecting virtualenv recognition.
- πΈ Directly Invoke virtualenv
- Attempt to directly execute virtualenv using its absolute path to confirm it's executable.
Command: /home/mycomputer/.local/bin/virtualenv --version
// should look like this:
LESSON_17_Virtual_Environment_and_pip$ /home/mycomputer/.local/bin/virtualenv --version
//
// Output Interpretation:
// If virtualenv is found and executable, it will output its version number.
virtualenv 20.26.3 from /home/mycomputer/.local/lib/python3.8/site-packages/virtualenv/__init__.py
- πΈ Check Visual Studio Terminal Settings
- (OPTIONAL) Review Visual Studio's terminal settings to ensure it has the correct permissions and environment settings to execute commands from
/home/dci-st119/.local/bin.
- πΈ Update Visual Studio Terminal PATH
π΄If Visual Studio's terminal does not recognize virtualenv, manually update its PATH setting.
- β Command (temporary update):
export PATH=$PATH:/home/mycomputer/.local/bin
- πΈ option
//1
echo 'export PATH=$PATH:/home/mycomputer/.local/bin' >> ~/.bashrc
//2
source ~/.bashrc
//
//This command uses source to execute (or "source") the commands from the .bashrc file in the current shell session. By doing so, it updates the PATH environment variable immediately in your current terminal session without the need to start a new shell.
//
// So, you would typically run these two commands consecutively in your terminal. The first command updates .bashrc to include /home/mycomputer/.local/bin in your PATH, and the second command refreshes your current shell session to apply this change.
- πΈ now check it:
TYPE: virtualenv --version
OUTPUT
virtualenv 20.26.3 from /home/mycomputer/.local/lib/python3.8/site-packages/virtualenv/__init__.py
-
creating the env with virtualEnv
-
choose the project where you are going to install the env folder, in my case i will choose
/LESSON_16_OOP
, once you have cd into that project, type the following:
virtualenv -p python3 env
// - -p python3: This specifies that you want to use Python 3 as the interpreter for creating the virtual environment.
//
// - If you omit the -p option, virtualenv will use the default Python interpreter that is available on your system when creating the virtual environment.
//
created virtual environment CPython3.8.10.final.0-64 in 307ms
creator CPython3Posix(dest=/home/mycomputer/Documents/ALL_SITE_3D_STUFF/3D-UNITY-BLENDER-REACTVR-ALL/0_PYTHON-all/PYTHON-PRIVAT/python-intro-2024-privat/LESSON_16_OOP/env, clear=False, no_vcs_ignore=False, global=False)
seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=/home/mycomputer/.local/share/virtualenv)
added seed packages: pip==24.1, setuptools==70.1.0, wheel==0.43.0
activators BashActivator,CShellActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator
- π env (folder)
- bin (folder, it includes the activation files and other stuff)
- lib (folder)
- gitignore
- pyvenv.cfg
- type the following command (you have to be on your project root)
source env/bin/activate
//
// like so:
LESSON_16_OOP$ source env/bin/activate
// the env is there, it means it works
/LESSON_16_OOP$ source env/bin/activate
(env) dci-st119@mycomputer:
π΄ Now tht i am inside the virtual environment like you can see in the below code, you can check the packages, type this command:
pip list
Package Version
---------- -------
pip 24.1
setuptools 70.1.0
wheel 0.43.0
/LESSON_16_OOP$ pip list
Package Version
---------- -------
pip 24.1
setuptools 70.1.0
wheel 0.43.0
(env) dci-st119@mycomputer:~/
- Now that I have the env setup, i can install stuff but ONLY in this env (environment)
pip install flask