Linking errors when using setuptools - python

I am extending C++ library with functionality that requires GRPC. GRPC dependencies are added through VCPKG (example from CMakeLists.txt):
find_package(gRPC CONFIG REQUIRED)
target_link_libraries(
mylib PRIVATE
gRPC::grpc++)
Now, that same library has python bindings (where I enter into, for me, an uncharted territory).
The library is built through setuptools. The setup itself initially went ok but when I try to load the library I get:
❯ python3
Python 3.8.10 (default, Nov 14 2022, 12:59:47)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mylib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/local/lib/python3.8/dist-packages/mylib-0.0.0-py3.8-linux-x86_64.egg/mylib.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZTIN6google8protobuf2io20ZeroCopyOutputStreamE
Missing _ZTIN6google8protobuf2io20ZeroCopyOutputStreamE clearly comes from GRPC dependency. I tried playing with setup.py and including grpc lib folder:
toolchain_args += ['-I/home/atomic/vcpkg/installed/x64-linux/lib']
I also tried extending required libraries list:
libraries += ['libgrpc++', 'libprotobuf']
Grpc is installed under /usr/local/lib/ and also as vcpkg package.
But without any luck. Including libs failed with following error:
/usr/bin/ld: cannot find -llibgrpc++
/usr/bin/ld: cannot find -llibprotobuf

Related

Python on Gentoo is missing sqlite

I use a Gentoo-based Docker image for CI with multiple versions of Python. Recently, I've started experiencing errors because one tool (coveralls) requires sqlite, which is missing. sqlite is part of the Python standard library.
This can be checked from the command line
>>> removing all .pyc files
>>> executing command
me#5b35f99c08af /source $ python
Python 3.6.9 (default, Dec 27 2019, 12:15:49)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sqlite3'
I couldn't find any notes in the Gentoo packaging database about this, but I'm not really familiar with it as an OS. I assume there must have been a problem building some relevant library.
Python has been installed like this:
RUN emerge -q -u dev-lang/python:3.6
But the error occurs for all the versions I'm currently testing with: >= 3.5. Any ideas as to what I'm doing wrong?

Difficulties starting JVM in Python using jpype

I have been using jpype to integrate with some java code using python lately and have been having no real issues. I am now attempting to set up my stack on a new system and am running into difficulties.
I am running 32-bit Python 3.6.5 and 32-bit oracle Java 1.8 update 171. Python and jpype have been installed using conda (conda create -n venv -c conda-forge python jpype1 arrow), and
jpype.getDefaultJVMPath() returns the expected path (C:\Program Files (x86)\Java\jre1.8.0_171\bin\client\jvm.dll), however an exception is raised stating that it could not find the module. The output from the python console below.
Python 3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 16:13:16) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import jpype
>>> import os
>>> jpype.__version__
'0.6.3'
>>> jvm_path=jpype.getDefaultJVMPath()
>>> jvm_path
'C:\\Program Files (x86)\\Java\\jre1.8.0_171\\bin\\client\\jvm.dll'
>>> os.path.exists(jvm_path)
True
>>> jpype.startJVM(jvm_path)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\User\AppData\Local\conda\conda\envs\venv\lib\site-packages\jpype\_core.py", line 70, in startJVM
_jpype.startup(jvm, tuple(args), True)
RuntimeError: Unable to load DLL [C:\Program Files (x86)\Java\jre1.8.0_171\bin\client\jvm.dll], error = The specified module could not be found.
at native\common\include\jp_platform_win32.h:58
>>>
What am I missing and/or doing wrong here?
In digging thru differences between the3 windows systems that I have been working on (2 working and this one that was not working) I found that the Microsoft Visual C++ 2010 Redistributable Package (x86) had been installed on the previous 2 systems but not the one exhibiting this behavior.
Installing the C++ redistributable immediately corrected the issue.

Python 2 Bindings Net-SNMP Error - undefined symbol: netsnmp-memdup

I successfully compiled net-snmp-5.7.3 on Ubuntu. :D This is the specific version of Ubuntu:
Linux loserBox 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:08 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
I seemed to have successfully installed the Python bindings for net-snmp too. This is included with the net-nsmp download as a different folder titled 'Python' with the setup.py file in it. However when running the command python setup.py test I noticed some problems. I thought this may be nothing to worry about so I went ahead and executed python setup.py install I was not sure what the instructions meant in the README file that say, "python setup.py test (requires a locally running agent w/ config provided)". So, this is why I installed it with the failed test or something. Anyways, I am not sure if this is a problem or not.
After successfully installing the python bindings for net-snmp I switched directories back to my Desktop and opened up an interactive python shell. From here I imported the netsnmp module and received the below error. It almost looks like there is a spelling error in the variable netsnmp_memdup that is throwing the error in the Traceback. This looks like a problem with the C code and not python.
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import netsnmp
/usr/lib/python2.7/dist-packages/pkg_resources.py:1031: UserWarning:
/home/loser_user/.python-eggs is writable by group/others and vulnerable to attack
when used with get_resource_filename. Consider a more secure location
(set with .set_extraction_path or the PYTHON_EGG_CACHE environment variable).
warnings.warn(msg, UserWarning)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/__init__.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client.py", line 1, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 7, in <module>
File "build/bdist.linux-x86_64/egg/netsnmp/client_intf.py", line 6, in __bootstrap__
ImportError: /home/loser_user/.python-eggs/netsnmp_python-1.0a1-py2.7-linux-x86_64.egg-
tmp/netsnmp/client_intf.so: undefined symbol: netsnmp_memdup
Does anyone know how to fix this problem? I looked on the mailing list page on sourceforge for this project and searched the supoort archives but did not find anything.
Thanks for listening to a crazy man's Python problems.
Happy Holidays,
user_loser
Alrgihty, thanks to my good friend Naveen, we have traced this down to an actual bug in the Python Net-SNMP bindings in the 5.7.3.
There are two ways around this:
Use the Python bindings in Net-SNMP 5.7.2
See this commit on our fork of the Net-SNMP Python library (only started yesterday so bear with us): https://github.com/fgimian/easysnmp/commit/fa86af977b563f65e7d70243752d48b94a8d5686 and replicate this in your download of Net-SNMP.

How to import bitarray using pypy?

I am running pypy and after adding the path to the bitarray library to sys.path I still can't import the module:
Python 2.7.3 (87aa9de10f9ca71da9ab4a3d53e0ba176b67d086, Feb 10 2014, 05:26:49)
[PyPy 2.2.1 with GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``every VM should come with neural
network trained to recognize microbenchmarks and randomly fluctuate them
+/-9000%''
>>>> import sys
>>>> sys.path.append('/usr/local/lib/python2.7/dist-packages/')
>>>> sys.path.append('/usr/local/lib/python2.7/dist-packages/bitarray/')
>>>> import bitarray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/bitarray/__init__.py", line 11, in <module>
from bitarray._bitarray import _bitarray, bitdiff, bits2bytes, _sysinfo
ImportError: No module named bitarray._bitarray
In regular python (CPython installed from aptitude) importing bitarray works fine and I haven't made any modifications to the module after installing it with pip. What's wrong here?
Just in case you need it here is the content of the bitarray dir:
$ls /usr/local/lib/python2.7/dist-packages/bitarray/
_bitarray.so __init__.py __init__.pyc test_bitarray.py test_bitarray.pyc
UPDATE
After creating a virtualenv for pypy and installing bitarray with pip as Sunny suggested I still get an ImportError:
$ ls my-pypy-env/site-packages/bitarray
_bitarray.pypy-22.so __init__.py __init__.pyc test_bitarray.py test_bitarray.pyc
$ cd my-pypy-env/
~/my-pypy-env$ ./bin/activate
~/my-pypy-env$ pypy
Python 2.7.3 (87aa9de10f9ca71da9ab4a3d53e0ba176b67d086, Feb 10 2014, 05:26:49)
[PyPy 2.2.1 with GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``__xxx__ and __rxxx__ vs operation
slots: particle quantum superposition kind of fun''
>>>> import sys
>>>> sys.path.append('/home/sofia/my-pypy-env/site-packages/bitarray')
>>>> import bitarray
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named bitarray
UPDATE 2
Sunny's solution is correct. The new problem was appending /site-packages/bitarray
instead of just /site-packages/. I would have though that virtualenv would add this to the path automatically but it seems that it doesn't.
The _bitarray module looks like a CPython extension, which is written directly in C.
CPython extension modules does not work directly in PyPy without any changes. You either need to install PyPy compatible version of the module, or do the required changes manually.
To install pypy compatible version, use the following commands:
# If pypy is installed globally
/path/to/pypy/pypy-2.1/bin/pip install bitarray
# If using virtualenv
source /path/to/virtualenv/env/bin/activate
pip install bitarray
Here are a couple of links from PyPy FAQs about this issue:
http://doc.pypy.org/en/latest/faq.html#module-xyz-does-not-work-with-pypy-importerror
http://doc.pypy.org/en/latest/faq.html#do-cpython-extension-modules-work-with-pypy

Python 2.5.2 and Solaris 8 (gcc 3.4.2) build issues

I'm trying to build python 2.5.2 on Solaris 8 using gcc 3.4.2. I can't see any immediate errors in the ./configure step but, once built and i enter the python shell doing an import time errors with :
Python 2.5.2 (r252:60911, Nov 21 2008, 18:45:42)
[GCC 3.4.2] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> import time
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named time
What am i doing wrong? From what i can see with a cursory google is that there might be an error with libstdc++.so, but i can't find any hard details.
Any suggestions would be most welcome.
Many thanks,
Al.
The time module is not built by default in Python, if you build from a source distribution you need to explicitly enable all the modules you want to compile.
Open up Modules/Setup.dist in the python source tree and comment out the line which says:
#time timemodule.c
To enable the build of time module. Also remember that you need to recompile Python for this to take an effect.

Categories

Resources