Use modules from venv in a started Process
Hey Guys,
I started to develop a small application in python. Unfortunally I have absolutely no expirience with python.
But as I started I got impressed by the module "venv" to create a virtual module, so I can install my dependend modules there and don't change my actual environment.
Now I have to start another python process inside the program, but using my python.exe I get the error, that python don't know my modules. (they are installed in the virtual environment)
I want to put the python.exe inside my own executable application, so the app is working on each device, unless python interpreter is installed or not.
I want to start another python script in my code:
This should run the script HTMLViewer.py with filepath and encoding as parameters with my python.exe which i copied into the ./assets/executables/ folder.
Problem is, that while debugging, the python.exe gets started, but has a problem with the HTMLViewer.py, because it imports modules which are installed in the venv.
But even when compiling the whole script into a executable with
(client.spec includes all assets etc. i need to run) the HTMLViewer.py is not started correctly.
What can I do, to use the modules used in my venv in the started python.exe or why does it not work after I compile to a executable (modules should be included?)
Thanks for your help in advance,
Micha
I started to develop a small application in python. Unfortunally I have absolutely no expirience with python.
But as I started I got impressed by the module "venv" to create a virtual module, so I can install my dependend modules there and don't change my actual environment.
Now I have to start another python process inside the program, but using my python.exe I get the error, that python don't know my modules. (they are installed in the virtual environment)
I want to put the python.exe inside my own executable application, so the app is working on each device, unless python interpreter is installed or not.
I want to start another python script in my code:
self.__topic[topic] = Popen(
# runs the executable HTMLViewer.exe with the path of the HTML file and encoding
["assets/executables/python.exe", resourcePath("assets/modules/HTMLViewer.py"), file, encoding]
)
Problem is, that while debugging, the python.exe gets started, but has a problem with the HTMLViewer.py, because it imports modules which are installed in the venv.
But even when compiling the whole script into a executable with
pyinstaller --onefile --windowed client.spec
What can I do, to use the modules used in my venv in the started python.exe or why does it not work after I compile to a executable (modules should be included?)
Thanks for your help in advance,
Micha
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 33515909516
Url: https://administrator.de/contentid/33515909516
Ausgedruckt am: 24.11.2024 um 10:11 Uhr
5 Kommentare
Neuester Kommentar
This should answer your question
https://docs.python.org/2/tutorial/modules.html#
Regards.
https://docs.python.org/2/tutorial/modules.html#
When a module named "spam" is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named "spam.py" in a list of directories given by the variable sys.path. sys.path is initialized from these locations:
After initialization, Python programs can modify sys.path. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section Standard Modules for more information.
- the directory containing the input script (or the current directory).
- PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
- the installation-dependent default.
After initialization, Python programs can modify sys.path. The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended. See section Standard Modules for more information.
I want to put the python.exe inside my own executable application, so the app is working on each device, unless python interpreter is installed or not.
But this will only work if the used python exe is compiled against the platform where it is executed.Regards.
Yes.