Virtual Environment is good to make sure that you’re using the right libraries in your code and also to not mixed different versions of libraries with different projects using the same library.
To create a virtual environment, follow the steps:
- Create a folder in your desktop that it’s not include in the github folder or the project folder. You could do this using cmd:
mkdir virtenv
cd virtenv
- Check if you have pipenv installed, if not just intall it:
pip install pipenv
- THIS IS NOT WORKING (14-12-2022) Then initiate the virtual enviorment with the comment (make sure that you are typing in the right directory) (skip if not working):
pipenv –-three
- Start the virtual environment
pipenv shell
- Now you can install any package you want if the comand:
pipenv install <package_name>
First, within the the virtual environment folder you need to have a .txt file with all the necessaries packages with the versions, like that:
Then just run:
pipenv install -r "requirements.txt"
If you want to see the libraries used in your virtual environment:
pipenv graph
If you want to delete some package, just type:
pipenv uninstall <package_name>
If you were with the VS code opened it’s better to restart it before trying to use the new virtual environment.
-
Choose the folder name that you created the virtual environment
- If “pipenv” **** function returns error, rewrite the command with following prefix: python3 -m <your syntax>