Dadoum / pyprovision

Python bindings to [Provision](https://github.com/Dadoum/Provision)
Other
12 stars 1 forks source link

ld: library 'python3.10' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) #3

Closed LongMeters closed 8 months ago

LongMeters commented 9 months ago

when i run 'pip install .' in console of pycharm,i found this error; venv for python3.10

Dadoum commented 9 months ago

Which OS are you using?

If you're on Linux, you just have to install Python development libraries on your system.

LongMeters commented 9 months ago

macos 14.1.2,thank you for your reply

Dadoum commented 9 months ago

Thanks for your interest in my project to begin with.

How did you install Python? Try to install it through brew.

LongMeters commented 9 months ago

i installed python with 'brew install python@3.10',and my mac's chip is M2Max

JayFoxRox commented 8 months ago

I have the same issue, also on macOS but with python3.11 (from brew); using ldc.

I hacked the pyd dub.json to have this (mostly from python3.11-config):

 "libs-posix": [
-                               "python3.11"
+                               "dl"
+                       ],
+                       "cflags-posix": [
+                               "-I/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11",
+                               "-I/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/include/python3.11",
+                               "-Wsign-compare",
+                               "-Wunreachable-code",
+                               "-fno-common",
+                               "-shared",
+                               "-undefined dynamic_lookup",
+                               "-DNDEBUG",
+                                "-g",
+                                "-fwrapv",
+                                "-framework CoreFoundation",
+                                       "-framework Python"
+                       ],
+                       "lflags-posix": [
+                               "/opt/homebrew/opt/python@3.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/config-3.11-darwin/libpython3.11.a"
                        ],

and in this project I have:

diff --git a/setup.py b/setup.py
index 047dee6..578d247 100644
--- a/setup.py
+++ b/setup.py
@@ -11,7 +11,7 @@ class DubExtension(Extension):

     def __init__(self, name):
         # don't invoke the original build_ext for this special extension
-        super().__init__(name, [])
+        super().__init__(name, [], libraries="libpyprovision.dylib")
         # self.source_dir = pathlib.Path(source_dir).resolve()

@@ -36,9 +36,11 @@ class DubBuildExt(build_ext):
         major, minor = sys.version_info[:2]
         minor = minor if minor <= 11 else 11
         self.spawn(['dub', "build", "-c", f"python{major}{minor}" , "-b", "release"])
         print(extdir)
         os.chdir(str(cwd))
-        shutil.copyfile(extdir_real / "libpyprovision.so", extdir)
+        shutil.copyfile(extdir_real / "libpyprovision.dylib", extdir)

(the "libraries" are necessary because if sources are empty, then clang will complain about not having any input files)

I actually get this problem now:

 % python3
Python 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyprovision
>>> dir(pyprovision)
['ADI', 'ClientProvisioningIntermediateMetadata', 'Device', 'OneTimePassword', 'ProvisioningSession', 'SynchronizationResumeMetadata', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__']
>>> pyprovision.ADI("/tmp/")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot create 'pyprovision.ADI' instances
JayFoxRox commented 8 months ago

I tried to check if the libs get loaded with DYLD_PRINT_LIBRARIES=1 DYLD_PRINT_LIBRARIES_POST_LAUNCH=1 (although I'm not sure what exactly each part does.. but I assume this is the D-API for pyprovision.cpython-311-darwin.so which is the C-API for Python?).

It doesn't seem to load libpyprovision.dylib when importing pyprovision.

Forcing to load it ahead of time causes a crash when importing pyprovision:

% DYLD_INSERT_LIBRARIES=/[...]/libpyprovision.dylib python3
Python 3.11.6 (main, Oct  2 2023, 13:45:54) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyprovision
zsh: segmentation fault