Installing libLAS on docker python - No such file or directory - python

I'm working in python in docker, and I need to add the package libLAS.
I usually just add a simple line to my dockerfile, for libLAS it would is:
Run pip install liblas
Docker seems to be able to build the image, but when I run a python script with the line:
import liblas
it gives the error:
Traceback (most recent call last):
File "/src/test.py", line 6, in <module>
import liblas
File "/usr/local/lib/python2.7/dist-packages/liblas/__init__.py", line 2, in <module>
from .core import get_version
File "/usr/local/lib/python2.7/dist-packages/liblas/core.py", line 158, in <module>
las = ctypes.CDLL(lib_name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
self._handle = _dlopen(self._name, mode)
OSError: liblas_c.so.3: cannot open shared object file: No such file or directory
I don't know what this error message means. Can someone please tell me how I can use liblas in python on docker?

You can add RUN apt-get -y install liblas-c3 in your Dockerfile and then Docker build . to install it.

You are just installing the python bindings. You need also to install liblas itself. If you are using Ubuntu/Debian, try
$ apt-get install liblas-c3

Related

Python FileNotFoundError: Could not find module 'venv\DLLs\libyara.dll' (or one of its dependencies) on Windows 11

In my Python code I use yara to compile yara rules.
The documentation located at
https://yara.readthedocs.io/en/stable/yarapython.html says that I can use it by importing it like this:
import yara
However when I run the code I get
FileNotFoundError: Could not find module 'C:\Users\bruker\Pycharmprojects\projectx\venv\DLLs\libyara.dll' (or one of its dependencies). Try using the full path with constructor syntax.
I am using a venv python enviroment for this project running in Windows 11.
I have tried the following:
pip install yara
pip install --upgrade --force-reinstall yara
pip install -I yara
pip install --ignore-installed yara
However I still get that the libyara.dll file is missing:
Traceback (most recent call last):
File "C:\Users\bruker\Pycharmprojects\projectx\deploygate.py", line 14, in <module>
import yara
File "C:\Users\bruker\Pycharmprojects\projectx\venv\lib\site-packages\yara\__init__.py", line 7, in <module>
from yara.rules import compile
File "C:\Users\bruker\Pycharmprojects\projectx\venv\lib\site-packages\yara\rules.py", line 17, in <module>
from yara.libyara_wrapper import *
File "C:\Users\bruker\Pycharmprojects\projectx\venv\lib\site-packages\yara\libyara_wrapper.py", line 315, in <module>
libyaradll = cdll.LoadLibrary(library)
File "C:\Users\bruker\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 452, in LoadLibrary
return self._dlltype(name)
File "C:\Users\bruker\AppData\Local\Programs\Python\Python310\lib\ctypes\__init__.py", line 374, in __init__
self._handle = _dlopen(self._name, mode)
FileNotFoundError: Could not find module 'C:\Users\bruker\Pycharmprojects\projectx\venv\DLLs\libyara.dll' (or one of its dependencies). Try using the full path with constructor syntax.
How can I fix the yara dll file missing? I am using Python 3.10.

No user_config.py

We have an internal wiki and I want to use pywikibot to get some data from it. Installed it from pip but when I import it I get:
>>> import pywikibot
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.7/site-packages/pywikibot/__init__.py",
line 25, in <module>
from pywikibot.bot import (
File "/usr/local/lib/python3.7/site-packages/pywikibot/bot.py", line
105, in <module>
from pywikibot import config2 as config
File "/usr/local/lib/python3.7/site-packages/pywikibot/config2.py",
line 373, in <module>
base_dir = get_base_dir()
File "/usr/local/lib/python3.7/site-packages/pywikibot/config2.py",
line 367, in get_base_dir
raise RuntimeError(exc_text)
RuntimeError: No user-config.py found in directory '/vagrant'.
Looking here https://www.mediawiki.org/wiki/Manual:Pywikibot/Installation#Configure_Pywikibot
I see a reference to pwb.py, but that does not exist in
/usr/local/lib/python3.7/site-packages/pywikibot.
What am I missing here?
Thanks!
Installing pywikibot from pip currently only installs the library part. The pwb.py and related console scripts are not included in the PyPI package. That means that you'll need to create the user-config.py manually or download the scripts in some other way.
I believe most pywikibot users just clone the git repo. The general process would be something like this:
git clone https://github.com/wikimedia/pywikibot.git --depth 1
python3 -m pip install -U setuptools
python3 -m pip install -e pywikibot/
cd pywikibot/
python3 pwb.py generate_family_file.py https://url.to.your/wiki/api.php? mywikiname
python3 pwb.py generate_user_files.py
# follow the prompts
Adding generate_family_file is in active development:
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/634544
The other two script will follow later I guess.

python generating netaddr error when running code

I am trying to get a piece of software called Probemon working and have come up with an error when I try to run it.
As I have both python2 and python3 installed (as per default installation) so I am running the command:
root#root:~/probemon/src$ python2 ./probemon.py -h
Traceback (most recent call last):
File "./probemon.py", line 11, in <module>
import netaddr
File "/usr/local/lib/python2.7/dist-packages/netaddr-0.8.0-py2.7.egg/netaddr/__init__.py", line 18, in <module>
from netaddr.core import (AddrConversionError, AddrFormatError,
File "/usr/local/lib/python2.7/dist-packages/netaddr-0.8.0-py2.7.egg/netaddr/core.py", line 11, in <module>
from netaddr.compat import _callable, _iter_dict_keys
File "/usr/local/lib/python2.7/dist-packages/netaddr-0.8.0-py2.7.egg/netaddr/compat.py", line 93, in <module>
import importlib_resources as _importlib_resources
File "/usr/local/lib/python2.7/dist-packages/importlib_resources-3.0.0-py2.7.egg/importlib_resources/__init__.py", line 5, in <module>
from ._common import (
File "/usr/local/lib/python2.7/dist-packages/importlib_resources-3.0.0-py2.7.egg/importlib_resources/_common.py", line 9, in <module>
from ._compat import (
File "/usr/local/lib/python2.7/dist-packages/importlib_resources-3.0.0-py2.7.egg/importlib_resources/_compat.py", line 42, in <module>
from zipp import Path as ZipPath # type: ignore
File "/usr/local/lib/python2.7/dist-packages/zipp-3.1.0-py2.7.egg/zipp.py", line 217
def open(self, mode='r', *args, pwd=None, **kwargs):
^
SyntaxError: invalid syntax
I am not sure what this error is trying to indicate...
Prior to this I have run these commands:
git clone https://github.com/drkjam/netaddr
cd netaddr
sudo python setup.py install
cd
git clone https://github.com/secdev/scapy.git
cd scapy
sudo python setup.py install
to ensure both netaddr and scapy dependencies are installed
To me, the error looks to have a problem with line 11 import netaddr however IF this is the case, I have already installed this, so I am not sure where the problem lies.
I have also tried running sudo python setup.py install for netaddr and scapy as sudo **python2** setup.py install in their respective directories just in case this made any difference which it did not.
Can anyone tell me what what the error is indicating please.
Thanks

OSError: libusb-1.0.so: cannot open shared object file: No such file or directory while building docs in readthedocs

I am trying to build documentation in readthedocs for a python module.
In my python module, I import libusb using command import libusb. libusb package requires a libusb-1.0-0 Debian package which is usually installed via sudo apt install libusb-1.0-0.
It seems the readthedocs server doesn't have libusb-1.0-0. Hence I get the following message in readthedocs:
File "/home/docs/checkouts/readthedocs.org/user_builds/strym/envs/latest/lib/python3.7/site-packages/usb1/__init__.py", line 61, in <module>
from . import libusb1
File "/home/docs/checkouts/readthedocs.org/user_builds/strym/envs/latest/lib/python3.7/site-packages/usb1/libusb1.py", line 199, in <module>
libusb = _loadLibrary()
File "/home/docs/checkouts/readthedocs.org/user_builds/strym/envs/latest/lib/python3.7/site-packages/usb1/libusb1.py", line 173, in _loadLibrary
return dll_loader('libusb-1.0' + suffix, **loader_kw)
File "/home/docs/.pyenv/versions/3.7.3/lib/python3.7/ctypes/__init__.py", line 356, in __init__
self._handle = _dlopen(self._name, mode)
OSError: libusb-1.0.so: cannot open shared object file: No such file or directory
As a result, my documentation is not generated.
How should I fix this?
Responding to #eric-wiener
I had given up on that and later I changed my requirements for not to need libusb. However, now that my understanding has become richer, I can suggest doing something like this: Add the following lines to the .travis.yml file:
before_install:
- sudo apt-get -y install libusb-1.0-0-dev
Let me know if it works. If it works then I can mark this as an accepted answer.

Passing Python3 to virtualenvwrapper throws up ImportError

I'm trying to use the virtualenvwrapper to make a python 3 based virtualenv. However,I'm when I pass the optional interpreter argument, I'm seeing this error. I'm running Ubuntu 15.04. I tried reinstalling virtualenv and virtualenvwrapper without success. Thanks for all your help!
$ mkvirtualenv scriptcutter --python=/usr/bin/python3
Running virtualenv with interpreter /usr/bin/python3
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 53, in apport_excepthook
if not enabled():
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 24, in enabled
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
Original exception was:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 8, in <module>
import base64
File "/usr/lib/python3.4/base64.py", line 9, in <module>
import re
File "/usr/lib/python3.4/re.py", line 336, in <module>
import copyreg
File "/usr/local/lib/python2.7/dist-packages/copyreg/__init__.py", line 7, in <module>
raise ImportError('This package should not be accessible on Python 3. '
ImportError: This package should not be accessible on Python 3. Either you are trying to run from the python-future src folder or your installation of python-future is corrupted.
I come across same issue, but after I downgrade virtualenv to 12.0.2, this problem disappears.
This is sort of a workaround for now.
Create a virtualenv using pyvenv.
# install pyvenv on Ubuntu
sudo apt-get install python3-venv
To minimize disruption in your normal workflow, pass a destination directory that is the same as the one used by virtualenvwrapper Like so,
pyvenv example ~/.virtualenvs/example
This is automatically working with workon and cdproject commands. I don't use much else that is provided by virtualenvwrapper
Hope this helps.
You can upgrade to the most recent version of virtualenv, with:
sudo pip install --upgrade https://github.com/pypa/virtualenv/archive/master.zip
virtualenv --version
# Returns 15.2.0.dev0 when I ran it
The following command then works:
mkvirtualenv scriptcutter --python=/usr/bin/python3
Apparently, the develop branch was dropped, so the URL with "develop" will no longer work. My answer was based off of #pjotr_dolphin's comment, with the URL updated.

Categories