#π VENV IN VSC
130 messages Β· Page 1 of 1 (latest)
@sacred talon
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
You are on Windows so source wouldn't work here.
You want venv\Scripts\activate.ps1 since you're in Powershell.
@scarlet blade that one is in VSC
\venv\Scripts\Activate.ps1 cannot be loaded because running
scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
- venv\Scripts\activate.ps1
-
+ CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess
You will need to allow Powershell to run scripts, and that can be done with this command:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
what about now
Relaunch your VSCode terminal and run the command I gave earlier.
I think VSCode might activate the venv for you when you do that but you can always run it just in case.
Also, just a word of caution, but you probably don't want to be developing your code within OneDrive, I've seen it cause problems in the past.
Again, it's venv\Scripts\activate.ps1.
same if i do the one you sent me
Can you share a screenshot of the whole terminal window?
!rule 4 hablo espaΓ±ol pero tenemos que hablar en ingles
4. Use English to the best of your ability. Be polite if someone speaks English imperfectly.
okay
remove the venv then make it again
why ?
because it's missing pyvenv.cfg which the activate script is trying to read
you could just go into the file explorer and delete it from there
the powershell equivalent would be rm -Recurse -Force venv
what abt now
make another terminal and run py -m venv venv (which you ran earlier)
and then the activate script
you've activated it now so that's great
you probably don't want it to be in the users folder though, so you should cd into the directory you want to build your project in, and make the venv there
what means the command cd?
oh yeah
that was i was gonna ask lol
how to
check this lol
weird
that's because it doesn't exist there.
the C:\Users\...> part at the left is the directory where you're currently in
you can use cd to navigate to directories within it
you can use ls to see the files and directories there
here, you're inside of a onedrive folder, so you'd want to cd there.
though again I'd probably recommend that you don't develop inside of onedrive and instead make some folder inside your users folder so that you can develop and use projects there
how do i take it out of onedrive lol
i copy and pasted the project into a new folder
but seem to show still at onedrive
the thing about OneDrive is that it likes to hide itself by basically moving folders like documents into being part of onedrive
so a folder that you would think is in your user folder is actually inside of onedrive
in your explorer window, go to %USERPROFILE% and make a new folder there (you could call it anything here but preferably something like projects or anything that's descriptive)
then go inside of your new folder, right click, and select the "open in terminal" option (or you could also get into the habit of making folders for each project you're developing and opening the terminal from there)
got the terminal, what should i do now?
you can do the steps that you did earlier to make the venv
!venv we went over that earlier. below are those same steps and it also serves as a general overview of venvs
Virtual environments are isolated Python environments, which make it easier to keep your system clean and manage dependencies. By default, when activated, only libraries and scripts installed in the virtual environment are accessible, preventing cross-project dependency conflicts, and allowing easy isolation of requirements.
To create a new virtual environment, you can use the standard library venv module: python3 -m venv .venv (replace python3 with python or py on Windows)
Then, to activate the new virtual environment:
Windows (PowerShell): .venv\Scripts\Activate.ps1
or (Command Prompt): .venv\Scripts\activate.bat
MacOS / Linux (Bash): source .venv/bin/activate
Packages can then be installed to the virtual environment using pip, as normal.
For more information, take a read of the documentation. If you run code through your editor, check its documentation on how to make it use your virtual environment. For example, see the VSCode or PyCharm docs.
Tools such as poetry and pipenv can manage the creation of virtual environments as well as project dependencies, making packaging and installing your project easier.
Note: When using PowerShell in Windows, you may need to change the execution policy first. This is only required once per user:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
you seem to be in cmd now so instead of Activate.ps1 you want activate.bat (i'll assume that you already made the venv).
refer to the overview here for the correct activate command, you're in the command prompt so things like ls won't work there
in CMD you would use dir instead of ls to list files in a directory
and to active your new venv in the .venv directory that you just made, run
.venv\Scripts\activate
is it active now?
yep, you can tell by the (.venv) at the start
ill try to wait 1s
got this one
it's not something critical, just kind of a warning that you are not running the latest version of pip and some instructions for how you can upgrade to the latest version if you want to, but you don't really have to
i have it but i cant see how to run it its weird
i think i see why now, you probably got the warning when you were running pip outside of your venv (when it wasn't activated)
when you start a new shell you need to activate the venv each time for each shell you launch where you want to be using that venv
you can see if you have your vemv active by looking at the start of the prompt, the name of the venv should appear within parenthesis at the very start of the prompt if it's currently activated in that shell
in this image you can see that it is missing
but the thing is the error is in a jupyter notebook, so how can i fix that to turn it into the jupyter
and this one you have cropped so much that we can't even tell
sorry, i don't use jupyter a lot, and the little i have used it was within vscode rather then through the web browser and there is didn't have that problem
but from this screenshot it doesn't look like you are executing jupyter from within the project directly where your venv directly lives, i don't know if that could have something to do with it
i'm also not used to windows, and especially not powershell, so i'm not sure how things work there with finding the right binary/executable
ohh u use linux
a lot of people been telling me to switch. i think i have to Lmao
but yeah if someone can help me out with the error i would appreciate it
nah, you don't have to switch, use what you are comfortable using or fit your situation best
still seem that is a little bit harder using python in windows
i just tried it on a windows computer that i can access using remote desktop
and i think i know what the problem is
in a new cell in the notebook, run
!where pip
```and see what it responds with
it's probably not the path that you are expecting if the venv would be activated π
@sacred talon π
the way i solved it was by running
!python -m ensurepip
```and let it run for a little while
then make sure that it works i run
```jupyter
!python -m pip list
```and you should get a list of everything that was installed in the venv for `jupyterlab`
then you should be able to install more stuff with
```jupyter
!python -m pip install pandas numpy
```and so on
@sleek iris on the topic of venv...
When creating virtual environments, is there any reason I should pip install virtualenv instead of just doing python -m venv myenv ? What would u recommend and why?
Thanks!
don't know, i never use the virtualenv module myself
i almost always use uv nowadays and it seem to be doing something similar to py -m venv .venv
and when i don't use uv i just use the venv module directly
yeah, and first now i realized that the last question wasn't from you
lmaooo π€£
where do i make the cell?
in the notebook in your web browser
like you did here
make a new cell that above the top cell, the new cell should contain
!python -m ensurepip
```then create yet another new cell just under the last new cell and put
```jupyter
!python -m pip list
```and check that you get a very long list of modules back
then change the beginning of the cell you had on-top so that it starts with
```jupyter
!python -m pip install
```followed by the modules you want to install
if you are happy with the results and don't have any further questions you can type !close to close the thread
well i have one but maybe is off topic lmao
do you know any statistics soccer API?
my project is based on that
if not theres not any problem lmao
no, sorry i don't
thank you tho for the help it was really helpful and i could learn
you're welcome π
love it bro thanks
upgrade these 2 guys to moderators lmao @sleek iris @scarlet blade
!close
This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.