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

OSError: error 0xc1 unable to load .pyd file on windows #27

Closed
hpca01 opened this issue Jul 31, 2019 · 3 comments
Closed

OSError: error 0xc1 unable to load .pyd file on windows #27

hpca01 opened this issue Jul 31, 2019 · 3 comments

Comments

@hpca01
Copy link

hpca01 commented Jul 31, 2019

Hi, I keep getting the following error:

error 0xc1  cannot load library 'C:\Users\a11123434\projects\venv\Lib\site-packages\xlsbconvert-0.0.1-py3.6-win32.egg\xlsbconvert\_native__lib.cp36-win32.pyd': error 0xc1

my setup.py:

from setuptools import setup

def build_native(spec):
    # build an example rust library
    build = spec.add_external_build(
        cmd=['cargo', 'build', '--release'],
        path='.'
    )

    spec.add_cffi_module(
        module_path='xlsb_csv._native',
        dylib=lambda: build.find_dylib('xlsb_csv', in_path='target/release'),
        header_filename=lambda: build.find_header('xlsb_csv.h', in_path='target'),
        rtld_flags=['NOW', 'NODELETE']
    )

setup(
    name='xlsb_csv',
    version='0.0.1',
    packages=['xlsb_csv'],
    zip_safe=False,
    platforms='any',
    setup_requires=['milksnake'],
    install_requires=['milksnake'],
    milksnake_tasks=[
        build_native
    ]
)

my cargo.toml:

[package]
name = "xlsb_csv"
version = "0.1.0"
authors = ["a random person [email protected]"]
edition = "2018"
build = "build.rs"

[lib]
name = "xlsb_csv"
path = "src/lib.rs"
crate-type=["cdylib"]

[dependencies]
calamine = "0.15.5"
csv = "1.1.1"

[build-dependencies]
cbindgen="0.9.0"

lib.rs:

#[no_mangle]
pub unsafe extern "C" fn a_test()->String{
    return String::from("abc")
}

xlsb_csv/init.py:

from xlsb_csv._native import ffi, lib

def test():
    return lib.a_test()

build.rs:

extern crate cbindgen;

use std::env;

fn main() {
    let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let mut config: cbindgen::Config = Default::default();
    config.language = cbindgen::Language::C;
    cbindgen::generate_with_config(&crate_dir, config)
      .unwrap()
      .write_to_file("target/xlsb_csv.h");
}

folder structure:

  • xlsb_csv\ __init__.py
  • src\lib.rs
  • cargo.toml
  • build.rs
  • setup.py
@hpca01
Copy link
Author

hpca01 commented Jul 31, 2019

fixed the ModuleNotFound error. Now I have a different error:
cannot load library '\venv\Lib\site-packages\xlsb_csv-0.0.1-py3.6-win32.egg\xlsb_csv\_native__lib.cp36-win32.pyd': error 0xc1

@hpca01 hpca01 changed the title ModuleNotFoundError on windows 10 64-bit OSError: error 0xc1 unable to load .pyd file on windows Aug 1, 2019
@hpca01
Copy link
Author

hpca01 commented Aug 1, 2019

Figured it out, had to change the rust toolchain because I have multiple versions of python installed(32bit vs 64bit). THANKS!

@hpca01 hpca01 closed this as completed Aug 1, 2019
@exarkun
Copy link

exarkun commented Sep 30, 2019

It would be pretty cool to have more details about what those changes were for anyone who runs into this problem and is looking for the workaround.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants