PC & IT SUPPORT MADE EASY FORUM
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Python3 VENV Setup For Windows & Linux

Go down

Python3 VENV Setup For Windows & Linux Empty Python3 VENV Setup For Windows & Linux

Post by jamied_uk 6th May 2023, 17:31

For Linux

Code:
sudo apt install python3.11-venv



Code:
python3 -m venv myenv



This will create a new virtual environment in a directory named myenv.

To activate the virtual environment, use the following command:


Code:
source myenv/bin/activate



This will activate the virtual environment and change your terminal prompt to indicate that you are now working within the virtual environment.

Note: If you are using the fish shell, the command to activate the virtual environment is slightly different. Use the following command instead:


Code:
source myenv/bin/activate.fish



Once you have activated the virtual environment, you can install any necessary packages using pip. For example, to install the requests package, use the following command:

Code:
pip install requests



To exit the virtual environment and return to your normal shell environment, use the following command:

deactivate


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


For Windows


Code:
cd C:\Users\YourUsername\Desktop\myproject



    Create the virtual environment by running the following command:

Code:
python -m venv myenv



This will create a new directory called "myenv" in your current directory, containing the files necessary to run a Python3 virtual environment.

    Activate the virtual environment by running the activate script in the "Scripts" subdirectory of your virtual environment. You can do this by typing:

Code:
myenv\Scripts\activate.bat


Last edited by jamied_uk on 30th June 2023, 11:24; edited 1 time in total
jamied_uk
jamied_uk
Admin

Posts : 2952
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Python3 VENV Setup For Windows & Linux Empty Re: Python3 VENV Setup For Windows & Linux

Post by jamied_uk 6th May 2023, 17:33

Code:
python.exe -m pip install --upgrade pip


pip install -r requirements.txt
jamied_uk
jamied_uk
Admin

Posts : 2952
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Python3 VENV Setup For Windows & Linux Empty Re: Python3 VENV Setup For Windows & Linux

Post by jamied_uk 9th June 2023, 08:39

To use a specific python version in venv

Code:
pip install virtualenv

Code:
virtualenv venv --python=python3.7




Code:
virtualenv myenv --python=C:\Users\USERNAME\AppData\Local\Programs\Python\Python37\python.exe

myenv\Scripts\activate.bat
jamied_uk
jamied_uk
Admin

Posts : 2952
Join date : 2010-05-09
Age : 41
Location : UK

https://jnet.sytes.net

Back to top Go down

Python3 VENV Setup For Windows & Linux Empty Re: Python3 VENV Setup For Windows & Linux

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum