PyCharm Virtual Environments (venv) Explained! | 10 Min. | Updated 2023
Vložit
- čas přidán 3. 08. 2024
- Learn to use virtual environments in PyCharm within 10 Minutes!
🔍 PyCharm Tutorial Playlist: • PyCharm Tutorials
⌚ Timestamps ⌚
00:00 | Two Methods of Creating a Virtual Environment (venv)
00:16 | Method 1: New Project with a Virtual Environment
01:34 | Method 2: Adding a Virtual Environment to Existing Projects
02:53 | Activating a Virtual Environment
06:11 | Error: "Activate.ps1 cannot be loaded because running scripts is disabled"
06:40 | Deactivate a Virtual Environment
06:58 | Installing Modules with PIP in a Virtual Environment
08:07 | Local Venv Modules vs. Global Modules
🌟 Please leave a LIKE and SUBSCRIBE for more! 🌟
◾◾◾◾◾ PyCharm Tutorials ◾◾◾◾◾
🐍 Install PyCharm & Python: • Install PyCharm & Pyth...
💿 PyCharm Basics in 10 Min.: • PyCharm Tutorial | Int...
◾◾◾◾◾ Learn Python ◾◾◾◾◾
🙂 Pygame Basics Series: • Pygame Tutorial - Intr...
🐺 Pygame Advanced Series: • Chrome Dinosaur in Pyt...
🤖 Python A.I. Series: • Video
◾◾◾◾◾ 🌎 Let's Connect! ◾◾◾◾◾
🐦 Twitter (X): 🔗 / @max_on_tech
📂 GitHub: 🔗 github.com/maxontech
🔊 Discord: 🔗 / discord
🏹 ProductHunt: 🔗 www.producthunt.com/@m4x
✅ Blog: 🔗 maxontech.io/courses
◾◾◾◾◾ Hashtags ◾◾◾◾◾
#PyCharm #Debug #Tutorial #Python
Something worth to mention is also that the pip in the virtual environment is a different one than the pip in the global environment. That's why you can also see a pip.exe in the venv directory in 4:28.
You don't always see the prompt (venv), indeed, that's quite common with customized shells with restrictions in corporate environment, but you still can find out which pip is relevant with `which pip` and then see the full path to it (either to global pip or to venv pip).
In addition, very often in Windows/corporate environment, you'll have to work with conda and pip together and then in a conda environment (what is then the necessary replacement for the virtualenv), you even have to first `conda activate ` and then run a `conda install pip` first, to have a pip in this environment (and otherwise, the global pip is silently taken without any notice about). And that's hard to debug if you are not aware that there might be different pip's (different locations, in different versions and with different behaviour, especially different install destinations, ...).
And while conda+pip together might not be so often, you'll often enough be in a situation where the PATH variable is not correctly set and then again silently the global pip instead of the local venv pip will be taken. Happens remote, in a CI/CD or outside of PyCharm, e.g. in CygWin or WSL2 often enough ...
I know it, because I often have to trouble shoot juniors 🙂in such situations.
Thank you for sharing this!
Let me explain why you did a GREAT job? Someone who has clicked on your tutorial most likely is not a graduate coder as such, slow, methodical, hold your hand approach is how we can learn and you nailed it. Great Great video and of course I subscribed. Keep up the excellent work.
hey, this is very encouraging! Thanks a lot!
You’re actually describing me - I’ve watched various videos and read articles, this was the first one that really made sense.
This helped a lot. I'm not a graduate programmer. I was walking in the dark when I stumbled upon this and it changed my life. I realized every project I had created on my pycharm didn't have a virtual environment and it was causing problems for me running them in the cmd. Kudos
Guess what? Until this video, I get lost each time I launch pycharm.Great job, we need teachers like u, so passionate! You made my 2023 a great one at last.
Hey, thanks! That's very encouraging :)
THAAAAAAAAAAAANKKKK YOUUUU! Short and clear, like it should be. Today I was messing around with it for about 4 hours and after 10 minutes of your video I finally get it. :)
Welcome :) let me know if there are any other topics that i should cover.
I was lost with PyCharm, this video helped me! Thanks Max!
Thank you so much! Most videos just showed the steps but you articulate everything under the hood. Amazing job!
awesome! hope it helped you understand everything:)
Very good, simple and clear, direct to the point ! Thanks
glad it helped :)
Amazing video, simple yet complete. Keep up the good work!
glad it helps people out there! all the best to you!
I was struggling with these, after watching this, everything is making sense, thanks!!
Hey, that's awesome! Glad it helped!
Man you have a natural gift for this! Thanks a lot!
thanks a lot! hope it helps :)
Thanks. Every basic video helps. Compared to all the programming I've done in the past, I am finding python exasperatingly confusing in many regards, despite all the books I am reading.
A very succinct tutorial! Thanks. Solved my venv problem.
Glad it helped!
Finally, it all made clear!! Thank you so much ❤
haha glad it did
thanks! concise and clear tutorial.
Most welcome! :)
really helped me understand each and everything perfectly. thanks
hey, thanks, that's awesome:)
Thank you very much that you included that Windows Error and solution. It drove me crazy. Now it works. Thank you, man. Subscribed. :)
yes, it rarely happens, really useful for that handful of people who get that error.
Thank youuu, I kept trying to figure this out and couldn't until i found your video
Glad I could help!
Thanks! This was exactly what I needed.
awesome :)
Very clear explanation. Much appreciated!
Awesome :)
Thank you for such a helpful video about virtual environments! It helps me reload my Python programming journey!
Glad it was helpful!
Outstanding explanation of venv. Best I've seen after having explored several other explanations..
awesome. feel free to let me know what else I should cover
This has been extremely helpful to me. Thank you
thanks :) glad it helped
That was sooooo helpful. Thank you so much!
Glad it was helpful! :)
Great tutorial. I had that PS script issue and this video helped me solve it.
awesome :) glad it helped!
thank you so much...
very simple and clear
hi :) glad it helped!
this fixed my issue, thank you so much
You're welcome!
This was very easy to follow, thanks
You're welcome!
Very good tutorial. Thank you, Max.
My pleasure!
Thanks man! Your solution was clear and precise. Worked perfectly for me. 👍
Awesome :) Glad it helped!
Thank you so much! Finally I've found your video and my first venv project just got activated. (have been trying for hours :$)
Hey, that's awesome :) glad it helped!
thank you so much for this video!
Glad it was helpful!
Thank you so much for your help 😇 and you save me from anxiety !
Hey, glad to hear it helped you :))
very clear tutorial, great job
awesome :)
Thank you so much for sharing!!!
Any time!
this tutorials help's me a lot thank you Max
Glad that it helps :)
Excellent, thank you
Glad it helped you!!
Thank you so much! Very helpful
Glad it helped!
Great video!!
yessir! Thanks!
this is awesome, thank you so much!
Welcome david :)
Thank you very, very much for your crystal clear explanation 😊
You are welcome!
Many thanks. you help me with your video.
that's awesome! Let me know if there's anything else you want me to cover.
Your way of explaining things is very good and understandable, clearly explained everything in detail for me I am a beginner and it helped me a lot. thanks
that's awesome! thanks a lot!
That was presented as a master class, thank you for your clear no frills direct tutorial, absolutely superb, will look at any other vid's you may have. Keep up the good work.
Thanks :) always enjoy reading these types of comments!
Great 👏🏻
thanks :)
thank you, other videos were showing on how to do it on cmd and i was confused. i didnt know there was a terminal in pycharm. video is really helpful.
You are welcome!
Thank you for this simple yet effective video. Your explaining is great keep it up🙂
Hi Diana :) thanks for the kind words. All the best, Max
..great explanation..
Glad it helped :)
GREAT!!
thanks!!
Thank you. a great help to beginners in python like me.
You're very welcome!
Great video :)
Thanks! glad these videos help :)
Thank You sir!
Most welcome!
thank u very much!!!!!!😊😊👌👌👍👍 PERFECT!
Glad it helped!
Thanks Max It is great video , very informative for us
hey :) glad it's still helpful
thankyou bro!👍🏼
most welcome!
Helpful.. thanks
Glad it was helpful!
Great
Thank you✌
You're welcome 😊
thank you brother
welcome! :)
Thnaks a lot. Hepled me!!!!!! you gained one subscriber
Thanks for the sub!
thanks thanks for excellent tutorial.
most welcome!
thanks!
Thanks you alot ❤❤❤❤ love you from nepal. Its really helped me alot.
That's awesome! Happy to help!
Great!
glad it helped. Let me know if there are other topics you want me to cover!
Thanks, just started using pycharm and am trying to follow a course I downloaded on selenium and test automation. The instructor is saying to run activate.bat instead of activate.ps1. This seems to have activated the environment.
keep up the good work
PowerShell command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
thanks!
thank you so much...
You're most welcome! :D
thanks sir
welcome!
thank you! very helpful
in next video if you can touch upon using/connecting anaconda and gitlab with pycharm will be great.
Very helpful video.
Form Bangladesh ❤❤
Glad it was helpful!
good video!
Thanks!
Thank you so much for this series of Pycharm, please keep adding more videos because they are really useful🙏🙏
Thank you, I will
06:34 saved my ass. Thanks for this wonderful tutorial bro!
awesome :) glad it helped!
pls send me the code, I cant do it
It's wok now, I am thankfull for this tutorial. Amazing
Thanks dude
Had to make some research for the command on powershell just for security and it was ok. Super simple
Hey Ray, glad it helped!
Thank you so much for your explanations regarding venv and in another video the interpreter but the question is why using venv, only to have our package in the project. I’m also installing packages in my projects without venv via pip3 install but then they are not available on pycharm. That’s because I don’t have venv? Thanks again very good content
Great video, details and how to jump in and out of venv, a minor correction if you don't mind, the file paths are separated by backslash \ in Windows, not slash / like in Linux
Yes, true, those slashes are confusing :D. Thanks for the info!
finally, loved it. It cleared my confusion. some questions I need to ask. To run a python program we have to be in a virtual environment first or it's just for installing packages only. 2nd question is how I can make separate python interpreter for different python projects? e.g project1---> python3.8 interpreter , project2------> python3.4 interpreter
Hi Hina, yes, you should also keep the venv on when you run your script. And you have the possibility to configure a new interpreter for each new project in the window that pops up when you create a new project :) hope it helps!
Is there a particular reason why you instruct in the usage of the Python Console inside PyCharm and not just the window under File -> settings ?
That window is very simple to use and the list of installed modules is right there.
Hi, I tried to install a new python interpreter "python 3.11" but it seems like the pycharm or maybe the python exe stays in a constant loop of the installation . So even after installing python the installation page pops again showing the "Modify, Repair, Uninstall" window of python and it just keeps re-appearing no matter which option I choose. Temporarily I choose the base interpreter which comes with pycharm itself but I want to change it to the latest asap can anyone tell me what's wrong with it or how can I fix it ?
Hi, thanks for this video.
I have a question. Why it is happening that during deactivation of venv my local terminal in pycharm doesn't see python and pip? How to install them correctly on my computer?
I wish i could like this video 1000 times
I had problem of powershell and it was fixed then.
How possible.Tnxxx
sup, glad I could help!
where should I put the code I am coding for example function library as I don't want to code in main(), inside vent folder or parallel to main, and how do I import in main ? tried and does not seem to recognize my local functional lib which is in project.
Thanks for the nice intro for beginners like me. I had the "rare" issue that you mentioned and tried what you said. However, setting the scope to CurrentUser did not work for me. So, I had to change it to LocalMachine instead. Now, I don't understand why it did not work and why it worked when I switched it. Can you help me understand?
Hi Biraj, would love to help you on this but frankly I'm not sure why the switch to LocalMachine fixed the issue ... Anyway, glad that you fixed the issue
What is the difference between using the venv and using existing environment? Is there any advantages and disadvantages?
Venv will save all dependencies (i.e., modules and libraries) to a folder specific to the project you are working on. Without venv you are going to install packages globally on your computer so that every project will have access to the modules and libraries - which is not good and in the video I explain why.
Hi, I'm using a Mac and my "problem" is two fold:
1) At 1:18 when setting up the virtual environment. On the left side under my sample project, it does not say "venv library root" like your directory does. Instead, that folder is named "VirtualEnv".
2) The terminal text is different. In the parentheses it reads "(VirtualEnv) USER@COMPUTERNAME sampleproject %". So when I try to write a command like "cd venv" I get this message: cd: no such file or directory: venv.
Please advise!
You are fckng best
haha thanks
There is no "Scripts" shown in my pycharm. It has "bin" which has pckages and "lib" which has gitignore and pyvnev.cfg nested under it?
sir, in 3:30 wen i type the command LS,am not getting venv ..wat to do now
"venv" is not prompting when selecting the radio button. Is this because a venv exists on another project within the folder? The answer to this question is not clear.
Please, can you explain me: how can i run pycharm, venv with python ==3.6? (because Scrapy)
Thank you.
Hey Alvaro! To create a new virtual environment with a different version of Python in PyCharm, you can follow these steps:
Open your project in PyCharm.
Click on the File menu and select Settings.
In the left pane, click on Project: your_project_name, and then select Project Interpreter.
Click on the gear icon at the top right corner and select Add.
In the Add Python Interpreter window, select Virtual Environment and click on New Environment.
In the Create Virtual Environment window, select the base interpreter that you want to use
.
Enter the location where you want to create the new virtual environment.
Select the version of Python that you want to use.
Click on Create.
After creating the new virtual environment, select it from the list of interpreters and click on OK.
Your new virtual environment should now be created with the desired version of Python.
@@MaxOnTech Once more time many thanks to help me with this new steps. Obrigado. Best regards.
Still facing issues? Perhaps my venv write-up covers the problem: maxontech.io/courses/pycharm/using-virtual-environments-venv-in-pycharm
I need help. Now where do I code? In what file
So why not install all packages globally? What do I gain by installing a package to a virtual environment where it can’t be used for other projects?
Out of date with the new interface. There is no option to add an interpreter in the settings panel.
amazing video. Very beautifully explained all the use cases. You are subscribed.
awesome :) glad I could help!
I don’t want virtual environment. Every time I create new projects it goes to virtual environment but I want to create projects in main/global/local (whatever it calls I don’t know). Just show me the way how I avoid virtual environment?
How to create Project in Pycharm without virtual enivronment? I want to add it like you did in the video, but there is no option to create project without it. It would have been nice if you included that in the video.
When you create a new project there is a checkbox asking if you want to create one. Otherwise, you can always delete the venv folder. Both options lead to a project without venv.
@@MaxOnTech I still can't find that checkbox, but deleting the folder seems to do the trick. Thanks!
Hi mate I am not able to get power shell working in Pycharm it is dead could you point me in the right direction thank u
Sure, check my answer under your other comment. I've written it out there :) all the best, Max
I have venv in terminal but can't see venv under project? Could you help me?
hi zahiz, compare the path in the terminal to the one of the file in the file tree. I think they wont be the same. Make sure you open the file whose path is the one you see in the terminal. If this doesn't help, then post a screenshot into my discord and ill try to help there.
I need your help
When I open Virtualenv Environment 02:35
At location: Do I have to paste the path of Python ?
It just shows my location of downloads by default like (C:\Users\AVT\Downloads)
Idk what to do and OK option isnt highlighted to click on
Pls help
And if I set location for venv like (create a file) and Base Interpreter to Python and then clicked OK it opens Python to Modify Setup
And if I click Modify it says its successful and asks to close and after closing its opens up again to Modify Setup and its continuous.. Im new to this pls help me
The path should be something like: .../project-name/venv
you can make it manually if it doesn't look like that by default.
You should not add the folder youself because when the venv is created it will make the folder by default.
If this doesn't work, send a screenshot of the issue to my discord
@@MaxOnTech oh ok thanks for the reply
I will try again
I am following the same method but not getting venv , it showing me in the terminal same name as my folder name in place of venv as of yours . Please tell me what to do now
Hi Sourabh, are you getting any error message?
@@MaxOnTech sir I am following the same step as you have said in this video above but the place where venv is to be written at that place the folder name is there . As per your example sample project is written in place of venv in the terminal.
same problem with me it does not enter into venv
@@girlyvlogs1137 I think you should try this code in visual studio code (vs code) there you can easily create your virtual environment (venv) . I did the same for this code to run . I hope it will work for you too .