-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Set Up Virtual Environments
- Open a Windows PowerShell
- Navigate to your home directory
PS C:\Users\nrf46657>
- Navigate to your home directory
- Install the python package
virtualenvPS C:\Users\nrf46657> py -m pip install --user virtualenv
- Confirm install was successful
PS C:\Users\nrf46657> pip show virtualenv
Name: virtualenv Version: 20.17.1 Summary: Virtual Python Environment builder Home-page: https://virtualenv.pypa.io/ Author: Bernat Gabor Author-email: gaborjbernat@gmail.com License: MIT Location: c:\users\nrf46657\appdata\roaming\python\python310\site-packages Requires: distlib, filelock, platformdirs Required-by: - Create a virtual environment
- navigate to your project folder
PS C:\Users\nrf46657> chdir .\Desktop\GitHub\virtualenv-test-project\
- create a virtual environment named "virtualenv4"
PS C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project> python -m virtualenv virtualenv4
created virtual environment CPython3.10.5.final.0-64 in 2672ms creator CPython3Windows(dest=C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project\virtualenv4, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\nrf46657\AppData\Local\pypa\virtualenv) added seed packages: pip==22.3.1, setuptools==65.6.3, wheel==0.38.4 activators BashActivator,BatchActivator,FishActivator,NushellActivator,PowerShellActivator,PythonActivator- You can also be explicit in which python install youre using when creating the virtual environment
PS C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project> C:\Users\nrf46657\AppData\Local\Programs\Python\Python310\python.exe -m virtualenv venvName- Sidenote, venv vs virtualenv?
- The following will both work
python -m virtualenv virtualenv4python -m venv virtualenv4
- virtualenv library offers more features than the venv module
- The following will both work
- navigate to your project folder
- Activate the virtual environment (in Command Prompt, permissions issue prevents us from being able to activate virtual environments from windows PowerShell, otherwise you could use
PS C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project> virtualenv4\Scripts\activate)R:\>cd /d C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project>virtualenv4\Scripts\activate (virtualenv4) C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project>- You will now be using the virtual environment untill you:
- Close the terminal, or
- Use the deactivate command
(virtualenv4) C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project>deactivate
- You will now be using the virtual environment untill you:
- Packages in the virtual environment
- check the pre-installed packages on the virtual environment
(virtualenv4) C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project> pip list Package Version ---------- ------- pip 22.3.1 setuptools 65.6.3 wheel 0.38.4 (virtualenv4) C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project>pip install --upgrade pip Requirement already satisfied: pip in c:\users\nrf46657\desktop\github\virtualenv-test-project\virtualenv4\lib\site-packages (22.3.1)- install packages into the environment
(virtualenv4) C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project>python -m pip install pandas Collecting pandas Downloading pandas-1.5.2-cp310-cp310-win_amd64.whl (10.4 MB) ---------------------------------------- 10.4/10.4 MB 37.2 kB/s eta 0:00:00 Collecting pytz>=2020.1 Downloading pytz-2022.7-py2.py3-none-any.whl (499 kB) ---------------------------------------- 499.4/499.4 kB 82.2 kB/s eta 0:00:00 Collecting numpy>=1.21.0 Downloading numpy-1.24.1-cp310-cp310-win_amd64.whl (14.8 MB) ---------------------------------------- 14.8/14.8 MB 113.1 kB/s eta 0:00:00 Collecting python-dateutil>=2.8.1 Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB) Collecting six>=1.5 Using cached six-1.16.0-py2.py3-none-any.whl (11 kB) Installing collected packages: pytz, six, numpy, python-dateutil, pandas Successfully installed numpy-1.24.1 pandas-1.5.2 python-dateutil-2.8.2 pytz-2022.7 six-1.16.0 (virtualenv4) C:\Users\nrf46657\Desktop\GitHub\virtualenv-test-project>pip list Package Version --------------- ------- numpy 1.24.1 pandas 1.5.2 pip 22.3.1 python-dateutil 2.8.2 pytz 2022.7 setuptools 65.6.3 six 1.16.0 wheel 0.38.4
Metadata
Metadata
Assignees
Labels
No labels