Skip to content
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

Unable to use PyDate or to import datetime.date when linked staticly #2216

Closed
PanQL opened this issue Mar 8, 2022 · 2 comments
Closed

Unable to use PyDate or to import datetime.date when linked staticly #2216

PanQL opened this issue Mar 8, 2022 · 2 comments
Labels

Comments

@PanQL
Copy link
Contributor

PanQL commented Mar 8, 2022

Bug Description

When linked staticly to libpython3.7m.a, usage of PyDate::new will cause a core dumped. I also reproduce it in python 3.8 and 3.9.

Steps to Reproduce

  1. create a cargo project
    with main.rs:

use pyo3::types::*;
use pyo3::Python;

fn main() {
pyo3::prepare_freethreaded_python();
Python::with_gil(|py| {
let date = PyDate::new(py, 2010i32, 3u8, 7u8).unwrap();
println!("Hello, world! {}", date.to_string());
});
}

with Cargo.toml:

[dependencies]
pyo3 = { version = "0.16.1", default-features = false }

with pyo3 build config file:

implementation=CPython
version=3.7
shared=false
abi3=false
lib_name=python3.7m
lib_dir=/usr/local/lib
executable=/usr/local/bin/python3
pointer_width=64
build_flags=
suppress_build_script_link_lines=false

  1. cargo run and it will crash.

Backtrace

No response

Your operating system and version

centos 7

Your Python version (python --version)

python3.7.10

Your Rust version (rustc --version)

1.59.0-nightly (6db0a0e9a 2021-11-29)

Your PyO3 version

0.16.1

How did you install python? Did you use a virtualenv?

install python3.7 by follow steps:
curl -O -L https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz && tar zxvf Python-3.7.10.tgz
cd Python-3.7.10
./configure --enable-optimizations
CFLAGS="-fPIC"
make -j8 altinstall
export LD_LIBRARY_PATH=/usr/local/lib:${LD_LIBRARY_PATH}

Additional Info

No response

@PanQL PanQL added the bug label Mar 8, 2022
@davidhewitt
Copy link
Member

Can you share any error messages as part of the core dump?

Note that the datetime module is a separate native library. You may need to ensure that if you're redistributing some statically linked binary you include these modules (and other stdlib sources which you may want). It's also very possible you need some additional build flags, see #416. Might be better to try to use PyOxidizer project rather than trying to figure out the correct build.

@PanQL
Copy link
Contributor Author

PanQL commented Mar 9, 2022

Thanks! @davidhewitt
I use the config file generated by pyoxidizer with pyo3 and it works.

@PanQL PanQL closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants