I prefer to use virtualenv instead of venv from a terminal/cmd/powershell, which is better and faster for some reasons. Some say it's the same, which is not the case at all.. So I've not tried virtualenv inside of VScode and give it a try.
It would be nice if you created Best Practices playlist and gather all this tips, like using __name__ == __main__, creating virt env when starting new project etc...
Here are the commands: Mac OS: python3 -m venv .venv source .venv/bin/activate Windows: python -m venv .venv .\.venv\Scripts\activate (Please correct me if I'm wrong for Windows, I will update this comment)
I have just done it yesterday. Depending on which shell you use it might be correct. For example in Powershell you need to ".\.venv\Scripts\Activate.ps1" and also enable scripts in powershell. But scripts in PS is another topic
You might want to run the windows command to check the .venv directory since I believe that "python -m venv .venv" and "py -m venv .venv" produce different folder structures in .venv
Thanks a ton :) Is there a way to activate the VENV automatically when a new terminal window is opened? (.venv) is not coming when we open Terminal after closing the IDE. @Indently Plz reply
Excuse me, friend, I would like to ask you for help because when I try to create a virtual environment and write the python location in the terminal, I get the following error "Set-location: No position parameter found", just, I would like to know what mistake I made so that it does not detect it
I made some python based tools for our team and had a git repo for it. Everytime someone new joins, I needed to get them install needed libs and sometime conflicts happen. Since I found venv, the issue is partially solved. But now I face the issue on how to manage the venv with git. A tutorial for that would be appreciated.
Hello sir, when i use javascript in vs code and ctrl + s to save my code it will auto help me auto formatting, how can i do the same thing with python (.py file) in vscode
@@Indently Pipenv is: 1. More automatic, one command (`pipenv install`) creates virtual environment and file with dependices 2. Just type `pipenv shell` to activate environment 3. New module installation adds depedicies automatically 4. Type just `exit` to deactivate environment 5. If You want clone virtual environment on other computer just paste depedicies file (`Pipenv.lock`) and type `pipenv sync`. 6. To remove environment just type `pipenv --rm` 7. You can create a requirements.txt file for venv It is worth trying `pipenv`, at most it will not appeal to you.
I know that the "." makes the folder invisible on Mac OS, but to be honest it's just what I've been doing since I started programming in Python. I would love to hear from someone else whether there's any benefit of doing that other than hiding folders for a cleaner directory.
The “.” is helpful for alphabetical ordering as well. “venv” gets mixed in with other folders while “.venv” is at the top. It also makes it more explicit that it is not meant to be part of the codebase but rather a supporting config type folder… similar to the .vscode, .git folders, etc.
The command for windows doesn't work for me. I've been trying to activate mine in vscode even before you uploaded this video. It says and error message "cannot be loaded be because the running script is disabled in this system" Despite several stackoverflow questions, it doesn't help still. Cmd command works fine but powershell doesn't.
Someone else correct me if I'm wrong since I don't have Windows, but it sounds like this is more a setting that has to do with the security settings on your computer?
Maybe it has something to do with execution policies. Run powershell as admin and try the command Set-ExecutionPolicy -ExecutionPolicy Unrestricted and try again the activate command.
Actually, it's a great question. The number of cases where the regular install is sufficient far outweighs the cases where venv is useful (plus it is clunky to use even with a great explanatory video like this). ...so I rarely use venv. I would be interested to hear good use cases other than encapsulation of packages (which can be achieved with a simple requirements.txt file).
You didn’t really describe why virtual environments are helpful. Could be useful to describe using a requirements file in conjunction with a virtual environment. My preference for managing my virtual environments and dependencies is Poetry.
I actually didn't describe why they are helpful at all, but I covered how to create and activate them. I will consider the rest for another tutorial :)
Continuing with this topic, it's worth mentioning the use of pip freeze > requirements.txt to generate a list of installed packages and their versions and the subsequent installation of these packages from the generated requirements.txt file.
@@squishy-tomato 👍Certainly, Poetry offers distinct advantages over pip. However, for beginners and a general understanding of virtual environments and package installation for their projects, using pip is entirely sufficient.