PyO3 / PyO3/pyo3

Python shared object not found while using pyenv

Open
#1,576 6 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation needs-implementer
Dominant language
Rust
Stars
16.2k
Forks
1k
Avg merge
2d 6h
Merged PRs (30d)
66

Description

🐛 Python shared object not found while using pyenv

🌍 Environment
  • Your operating system and version: Windows 10 20h2 + WSL2
  • Your python version: 3.7.9
  • How did you install python (e.g. apt or pyenv)? Did you use a virtualenv?: env PYTHON_CONFIGURE_OPTS="--enable-shared" pyenv install 3.7.9
  • Your Rust version (rustc --version): rustc 1.51.0 (2fd73fabe 2021-03-23)
  • Your PyO3 version: *0.13.2
  • Have you tried using latest PyO3 main (replace version = "0.x.y" with git = "https://github.com/PyO3/pyo3")?: yes
💥 Reproducing

main.rs

use pyo3::prelude::*;
use pyo3::types::IntoPyDict;

fn main() -> Result<(), ()> {
    Python::with_gil(|py| {
        main_(py).map_err(|e| {
            // We can't display Python exceptions via std::fmt::Display,
            // so print the error here manually.
            e.print_and_set_sys_last_vars(py);
        })
    })
}

fn main_(py: Python) -> PyResult<()> {
    let sys = py.import("sys")?;
    let version: String = sys.get("version")?.extract()?;
    let locals = [("os", py.import("os")?)].into_py_dict(py);
    let code = "os.getenv('USER') or os.getenv('USERNAME') or 'Unknown'";
    let user: String = py.eval(code, None, Some(&locals))?.extract()?;
    println!("Hello {}, I'm Python {}", user, version);
    Ok(())
}

cargo run

Result

error while loading shared libraries: libpython3.7m.so.1.0: cannot open shared object file: No such file or directory

Workaround
export LD_LIBRARY_PATH=~/.pyenv/versions/3.7.9/lib

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the main.rs reproducer and run cargo run under the reported pyenv Python 3.7.9 installation, then compare the failure with LD_LIBRARY_PATH set to ~/.pyenv/versions/3.7.9/lib. Trace how the Rust executable locates the Python shared object; done means the reproducer runs without requiring that workaround or the required setup is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.