#๐ any python experts here?
39 messages ยท Page 1 of 1 (latest)
@sick harness
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 should make a venv and install in that.
!venv
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
this worked for me
Here's how you can setup a virtual environment in Visual Studio Code for Python.
โถ Become job-ready with Python:
https://www.indently.io
โถ Follow me on Instagram:
https://www.instagram.com/indentlyreels
if you are using bash ofc
also, kali isn't a good general usage linux distro, so if your code isn't for related to cybersecurity you might want to look at a more suitable distro
its for a course
a security related course that tells you to use kali?
API Penetration Testing by APIsec
in a vm
yeah? its not new for me lol
yeah, that sounds like a cybersecurity related course ๐
have you followed the suggestions above about using a venv?
omg
it work
worked*
thank you so much, God bless you!
wait
does it work outside the venv?
@main oriole
it can work outside a venv too
but it can also get messy that way
are you using the root account or sudo? (hint: you shouldn't be doing so)
this is because when you activate a venv it sets up some environment variables that python will use to find the modules local to that venv diir, which you won't have when it's not activated
you can however execute the python binary inside the venv to get the same effect without activating the venv
you can do this either by using the full path for that python interpreter binary and then the script that you want to run, but i don't think that is what you will prefer, an easier way is to change the shebang line at the top of your script to use the full/absolute path to that python interpreter binary that is located inside the venv
is there a way to be in the same venv again?
?
you can enter the same venv whenever you want by activating it again
this article goes into lengths about venvs and will probably answer all your questions about them and more https://realpython.com/python-virtual-environments-a-primer/
that article is also good since it uses all the current best practice (even for the different platforms), at least as far as i have seen
Again? Run the activate script again.
It's per terminal window/shell.
It does 2 things:
- hacks your $PATH to find the venv python when you invoke python
- hacks your prompt to remind you that you ran the activate script
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.