Python Virtual Environment (venv)
Python Virtual Environment (venv)
Pre-Req :
- This is on Mac
- Make sure Python3 is installed in the system
- $pip3 install virtualenv #--upgrade
- $virtualenv #help
Steps:
- create folder
- cd inside folderName
- $virtualenv env_name #-p /folder_path_of_python_to_clone/bin/python
- $source ./env_name/bin/activate
- #if u get permission denied "$chmod -R 777 *"
- #Note u can also have multiple environments and activate which ever u want
- Notice "env_name" in the Terminal line meaning it is activated.
- Try:
- $python
- import requests # you will get error
- exit()
- Try2 (make sure virtual env is still activated)
- $pip install requests
- $python
- import requests
- exit()
- $pip freeze > requirements.txt
- To install requirements from above file #pip install -r requirements.txt
- $deactivate #Deactivate the env
Note:
- To use Virtual Environment in Pycharm
- Preferences> Settings > Add > Virtualenv
- Make sure it is pointing to venv
No comments:
Post a Comment