-
Notifications
You must be signed in to change notification settings - Fork 844
PyO3 Fails to Import DLL in Python Virtual Environment on Windows #3589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I found that this issue is similar to #1896. I also found that the above steps work normally on Linux (with Ubuntu 22.1 as the system) when running tests with |
This is almost certainly a duplicate of #1896. It's on my list to solve eventually, I think it'll get easier when we can drop 3.7 support and adopt the new @luoshuijs, for now you should be able to workaround this by using |
Quite bad :-( It's still something like 1/4 of all of our downloads. From the metrics, a huge portion of the downloads comes from Amazon Linux 2. |
Thank you very much, @davidhewitt, for your response. However, after trying to set the PS K:\PycharmProjects\python_genshin_artifact> venv/Scripts/activate.ps1
(venv) PS K:\PycharmProjects\python_genshin_artifact>
(venv) PS K:\PycharmProjects\python_genshin_artifact> $env:PYTHONHOME="C:\Users\luoshuijs\AppData\Local\Programs\Python\Python311"
(venv) PS K:\PycharmProjects\python_genshin_artifact> $env:PYTHONPATH="C:\Users\luoshuijs\AppData\Local\Programs\Python\Python311"
(venv) PS K:\PycharmProjects\python_genshin_artifact> $env:PYTHONHOME
C:\Users\luoshuijs\AppData\Local\Programs\Python\Python311
(venv) PS K:\PycharmProjects\python_genshin_artifact> $env:PYTHONPATH
C:\Users\luoshuijs\AppData\Local\Programs\Python\Python311
(venv) PS K:\PycharmProjects\python_genshin_artifact> cargo test
Finished test [unoptimized + debuginfo] target(s) in 0.27s
Running unittests src\lib.rs (target\debug\deps\_python_genshin_artifact-9ae2f0247525dfea.exe)
error: test failed, to rerun pass `--lib`
Caused by:
process didn't exit successfully: `K:\PycharmProjects\python_genshin_artifact\target\debug\deps\_python_genshin_artifact-9ae2f0247525dfea.exe` (exit code: 0xc0000135, STATUS_DLL_NOT_FOUND) |
@luoshuijs did you sat |
Indeed, I forgot to set the |
Hello, I found the same problem on Windows with a venv. The compilation is fine, but when I tried to import the pyd file (just a copy of the compiled DLL) directly into Python, I got a DLL loading error. A really ugly solution was to use this line before importing the .pyd file into Python.
Now all's well. It seems that PyO3 doesn't link the right DLL directories on Windows from the package installed in the venv. Maybe it's looking for DLLs globally or something else. |
…nv it fails to link the DLL from the locally installed torch lib. Added a comment to an issue : PyO3/pyo3#3589 (comment)
#3589 (comment) still applies. I'd love to solve this soon, but my own priorities for time have been elsewhere. |
Okey thank you I completely understand, the best workaround I found was to use Linux directly and avoid this crappy Windows. |
Bug Description
When running
cargo test
within a python virtual environment on Windows, PyO3 fails to import DLLs, resulting in aSTATUS_DLL_NOT_FOUND
error. This occurs even after attempting to use--no-default-features
to exclude potential issues caused by default feature sets.Additional Attempt to Resolve:
Following the suggestion from the PyO3 FAQ, adding the directory containing the Python DLL (from the existing Python environment) to the PATH environment variable was attempted. However, this leads to importing modules from the existing Python environment instead of the virtual environment.
Steps to Reproduce
Set up a python virtual environment on Windows.
Create a minimal Rust project using PyO3.
Add a simple test case in src/lib.rs, for example:
Run the project using
cargo test
.Observe the error output.
Backtrace
No response
Your operating system and version
Win 10
Your Python version (
python --version
)Python 3.11.0
Your Rust version (
rustc --version
)rustc 1.71.0-nightly (4a59ba4d5 2023-05-12)
Your PyO3 version
0.19.2
How did you install python? Did you use a virtualenv?
python.org install
python -v venv venv
Additional Info
No response
The text was updated successfully, but these errors were encountered: