#๐ Where do I get activate_this.py? When I create a venv its not here
67 messages ยท Page 1 of 1 (latest)
@granite burrow
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.
how did you create your venv?
does it not have any activate script?
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
do source venv/bin/activate
yes, i know that but i want to activate the venv using the script to install dependencies with the sctipt
will that work
what script?
my own script
like a bash script?
python
its possible
so you're saying you wanna write your own python script, that activates the venv, then pip install the requirements?
its not the best way to do it but you probably need to use something like subprocess to execute host level commands
I wouldn't use it. I'd rather control my own installs
!d subprocess
Source code: Lib/subprocess.py
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions...
well yeah but i want to make the install more convinient for the users who arent knowledgeable about python
i know what subprocess is
what is this thing that you want users to install?
visit this repo https://github.com/mrbartix/btotp
ive asked my friend to install it and he had ...many problems with it and i had to guide him cuz he is a windows user and isnt knowledgeable with the windows terminal, hence the need for an installation script
Personally, I wouldn't use tkinter. Trying to compile it into a binary executable file causes problems with pyinstaller or nuitka or whatever. If you insist on using Python, consider building with Flet https://flet.dev and then properly build for each platform. For windows, you compile it and sign it properly via Visual Studio https://flet.dev/docs/publish/windows
Build multi-platform apps in Python powered by Flutter.
Flet CLI provides flet build windows command that allows packaging Flet app into a Windows application.
But its your project tho
There are easier ways to distribute your app but you have to find a way to properly bundle it first before you can distribute it
i am not going to rewrite this project cuz because tkinter isnt ideal
Thats completely fine
I suggested to compile it so its easier for the users to install your app
As opposed to writing a separate custom installer script
well but as you said ive heard that tkinter may not like being compiled
and also im halfway done with the script
its not tkinter that doesnt like being compiled. Its just not properly signed so it doesnt get flagged for viruses by MS Defender or whatever after its compiled
hm, as a test how do i compile it
pyinstaller? nuitka? beeware? idk. Try them. I've not compiled any Python GUI in a very long time and have opted a different language that does it better.
yeah python isnt really ideal for compilation
Well, i did this
def setup_venv(): # sets up the venv, and installs pip dependencies.
print("\nVenv setup")
print("[1/2] Setting up the venv")
subprocess.run([sys.executable, "-m", "venv", "venv"], cwd=f"{default_download_dir}/btotp-main", check=True)
print("[2/2] Installing pip dependencies")
subprocess.run([f"{default_download_dir}/btotp-main/venv/bin/pip", "install", "-r", "requirements.txt"], cwd=f"{default_download_dir}/btotp-main", check=True)
And it works
Cool
Thanks for help!
that or PySide6 for using Qt
that wonโt work, the venv will not remain activated when your command finishes
think of it like running each command in a new cmd window each time
but i dont need it to remain activated...?
oh, okay, now i see what you are doing ๐
yeah, you just run the pip from the path within the venv
that is the proper way of doing it
after setup() its gonna execute another function which will create a .desktop file which will execute path/vev/bin/python path/src/exec.py
Yeah
I cant really keep it activated
so i walked around it
i saw talk before about activating the venv and though that you were still trying that, but now when i look at the command more carefully i see that you do it correctly
exactly
yeah, and that is the correct workaround
it's the same when you want to execute a python script within the venv, you just use the path to the python executable within the venv and then the path to the script
yeah i wanted to do that, but i thought about it and realized that i cant activate it
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.