admin管理员组文章数量:1289529
There is a python library that only wants to be installed in a virtual environment, but how to import the library into scripts running in my standalone application that does not run in a virtual environment?
I'm writing a a Delphi/Lazarus application using the component Python4Delphi and Python4Lazarus to run python scripts.
There is a python library that only wants to be installed in a virtual environment, but how to import the library into scripts running in my standalone application that does not run in a virtual environment?
I'm writing a a Delphi/Lazarus application using the component Python4Delphi and Python4Lazarus to run python scripts.
Share Improve this question asked Feb 20 at 6:33 RimfireRimfire 4001 gold badge4 silver badges14 bronze badges 2- 2 In your Delphi/Lazarus application, you could configure Python4Delphi to use the Python interpreter from your virtual environment instead of the system Python. This way, it will automatically have access to all packages installed in that virtual environment. PythonEngine1.DllPath := 'PATH'; OR you can add the venv's package directory into your standalone application like: import sys import os venv_path = r"C:\path\to\your\venv\Lib\site-packages" if venv_path not in sys.path: sys.path.append(venv_path) # Now you can import your library import your_library – Cool Breeze Commented Feb 20 at 6:43
- Great info, that works. Even under Lazarus and Linux. Make it an answer. – Rimfire Commented Feb 20 at 7:01
1 Answer
Reset to default 2There are two ways you can try to fix this:
- In your Delphi/Lazarus application, you could configure Python4Delphi to use the Python interpreter from your virtual environment instead of the system Python. This way, it will automatically have access to all packages installed in that virtual environment.
PythonEngine1.DllPath := 'PATH';
- You can add the venv's package directory into your standalone application like:
import sys import os
venv_path = r"C:\path\to\your\venv\Lib\site-packages"
if venv_path not in sys.path:
sys.path.append(venv_path) # Now you can import your library import your_library
本文标签:
版权声明:本文标题:delphi - Using a python library installed in virtual environment from script running in standalone application - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741456026a2379759.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论