bsddb.btopen alternative on Google Colab? - python

So I have my Notebook on Google Colab using Python 3 (and I will implement some Deep learning libraries ex: Keras, TF, Flair, OpenAI...) so I really want to keep using Python 3 and not switch to 2.
However, I have a .db file that I want to open/read, the script is written in Python 2 because they are using bsddb library (which is deprecated and doesn't work on Python 3)
self.term_to_id = bsddb.btopen(resource_prefix + '_term_to_id.db', 'r')
I tried modifying the Python 2 file to make it compatible on Python 3 so I can import it as a module in my Google Colab Notebook, what I tried:
I tried changing bsdbb to bsdbb3, and installing !pip install berkeleydb so I can do that later !pip install bsddb3 and just update bsdbb to bsdbb3 , but upon installing !pip install berkeleydbI get the following errors:
ERROR: Could not find a version that satisfies the requirement
berkeleydb (from versions: 18.1.0, 18.1.1, 18.1.2, 18.1.3, 18.1.4)
ERROR: No matching distribution found for berkeleydb
2)I thought maybe I could just import the dependency from python 2 file to my Python 3 notebook, but as expected it didn't work because it didn't recognize 'import bsdbb' in the Python 2 file.
Any tips/ work around to make it work on Google Colab ?

berkeleydb is only Python binding on database BerkeleyDB created in C/C++.
When I try to install it on my local system Linux Mint then I see error with
FileNotFoundError: [Errno 2] No such file or directory: 'src/Modules/berkeleydb.h'
which means that it tries to compile some C/C++ code.
And this usually need to install special package with C/C++ headers (files .h) with suffix -dev.
Using
!apt search Berkelay
I found that there is installed libdb5.3 so I installed libdb5.3-dev
!apt install libdb5.3-dev
and after that Python can install berkeleydb
This works for me on Colab
!apt install libdb5.3-dev
!pip install berkeleydb
import berkeleydb as bsddb

Related

Cannot seem to download SimpleElastix: file.whl wheel not recognized/import not recognized

I'm trying to install SimpleElastix for python. As far as I can tell, you can either download a whl file from https://simpleelastix.github.io/#download
or simply pip install as shown here: https://pypi.org/project/SimpleITK-SimpleElastix/
I first tried downloading it and am trying to install SimpleITK-0.9.1rc1.dev163-cp34-cp34m-win_amd64.whl that I have saved to drive.
I am using the following (pip has been updated):
(hids3) C:\Windows\system32>python --version
Python 3.8.0
(hids3) C:\Windows\system32>pip --version
pip 22.0.4 from C:\Users\kated\anaconda3\envs\hids3\lib\site-packages\pip (python 3.8)
I try to run pip install SimpleITK-0.9.1rc1.dev163-cp34-cp34m-win_amd64.whl
and get the following error:
ERROR: SimpleITK-0.9.1rc1.dev163-cp34-cp34m-win_amd64.whl is not a supported wheel on this platform.
According to Error "filename.whl is not a supported wheel on this platform" , this could be caused by a downloading the .whl file for a wrong python version. I would expect python 3.8 to support a CPython 3.4 version or am I wrong for assuming this?
Alternative way to download SimpleElastix: https://pypi.org/project/SimpleITK-SimpleElastix/
I also tried running
pip install --user SimpleITK-SImpleElastix
in the terminal, which worked, but when I run
import SimpleITK as sitk
sitk.Elastix()
I get
AttributeError: module 'SimpleITK' has no attribute 'Elastix'
Anyone have any idea what I'm doing wrong in either case?

Unable to import pyodbc on Apple Silicon - Symbol not found: _SQLAllocHandle

I am currently working on a python (3.8) project on my 2021 MacBook Pro with Apple Silicon. Ultimately, the goal is to build a ML model on data I read from an Azure SQL DB using Apple's Tensorflow fork. Therefore, I am developing the project on native Apple Silicon packages - not using Rosetta.
The Problem arises when I try to import the pyodbc package (4.0.30) in order to connect to my DB. I keep getting the following error
File "<stdin>", line 1, in <module>
ImportError: dlopen({myvenv}/lib/python3.8/site-packages/pyodbc.cpython-38-darwin.so, 2):
Symbol not found: _SQLAllocHandle
Referenced from: {myvenv}/lib/python3.8/site-packages/pyodbc.cpython-38-darwin.so
Expected in: flat namespace
in {myvenv}/lib/python3.8/site-packages/pyodbc.cpython-38-darwin.so
If however, I do the exact same thing using Rosetta everything works fine. I couldn't find any other thread describing a similar behaviour.
Does anyone know how to resolve this issue?
My feeling is that the package is not compiled properly for ARM architecture.
You can uninstall the pyodbc and install it again. If using pip, it would be like this:
pip uninstall pyodbc
and install with compiling it locally:
pip install --no-binary :all: pyodbc
Do not forget on Unix/Linux like platforms, you need to download the pyodbc source distribution is build against an ODBC driver manager, os unixosbc is a prerequisite. Example installation with brew package manager:
brew install unixodbc
The not-compiled installation should work:
pip install --pre --no-binary :all: pyodbc
This compiles locally and is thus compatible and overcomes the issue.

Can't import nltk. Saying "ImportError: No module named collocations" [duplicate]

This question already has answers here:
Importing Libraries Issue - "ImportError: No Module named ____"
(2 answers)
Closed 5 years ago.
I've just installed nltk through pip using the command:
sudo pip install -U nltk
I've also installed numpy immediately in similar way, I tried to import nltk and test and typed 'import nltk' after typing 'python' in terminal, then I got this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "nltk.py", line 3, in <module>
from nltk.collocations import *
ImportError: No module named collocations
>>>
I tried to find solution online and found this link Importing Libraries Issue - "ImportError: No Module named ____",
so I tried this command: export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages, but nothing changed maybe because there the module itself is not found. I also tried to use the command
sudo pip install -U collocations
but it says
Collecting collocations
Could not find a version that satisfies the requirement collocations (from versions: )
No matching distribution found for collocations
When I first tried it also said
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
I couldn't upgrade directly but could upgrade when I used:
sudo -H pip install --upgrade pip
But still I'm getting the same thing. I'm really new to python and like to know if I'm doing anything wrong. I had to reinstall Ubuntu 16.04 recently so I think the operating system is working fine. Thank you very much
Edit: So there was a file called nltk.py in my home folder, maybe that was effecting this, I've removed the file but still it's getting created somehow when I try to import nltk and printing the same thing as above traceback....
The contents of the file were:
import sys
import nltk
from nltk.collocations import *
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
# change this to read in your data
finder = BigramCollocationFinder.from_words(
nltk.corpus.genesis.words('annotation/dataset.txt'))
# only bigrams that appear 3+ times
finder.apply_freq_filter(3)
# return the 10 n-grams with the highest PMI
finder.nbest(bigram_measures.pmi, 10)
please use virtualenv, because it is not good if you update or install python packages global, because e.g. ubuntu use some special package versions for their own software and if you change something this could create a lot of problems. You can install it with:
pip install virtualenv
Here is a link with a very good introduction how to use it.
This will probably solve your problem too. I tested it also with ubuntu 16.04 by myself.

python installing thread-local storage

I'm trying to install a pysnap library from github. This is part of the output I get. I have no idea how to proceed, any help would be greatly appreciated.
Installed /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pysnap-0.1.1-py2.7.egg
Processing dependencies for pysnap==0.1.1
Searching for cryptography>=1.2.2
Reading https://pypi.python.org/simple/cryptography/
Best match: cryptography 1.2.3
Downloading https://pypi.python.org/packages/source/c/cryptography/cryptography-1.2.3.tar.gz#md5=5474d2b3e8c7555a60852e48d2743f85
Processing cryptography-1.2.3.tar.gz
Writing /tmp/easy_install-7ZnmT5/cryptography-1.2.3/setup.cfg
Running cryptography-1.2.3/setup.py -q bdist_egg --dist-dir /tmp/easy_install-7ZnmT5/cryptography-1.2.3/egg-dist-tmp-rcoXcx
_configtest.c:1:1: error: thread-local storage is unsupported for the current target
__thread int some_threadlocal_variable_42;
1 error generated.
error: unable to create target: 'No available targets are compatible with this triple, see -version for the
available targets.'
1 error generated.
What platform are you trying to install pysnap?
I downloaded and installed pysnap sucessfully from this github location
I do have windows 10 platform and python 2.7 though. I dont' have a linux to replicate this issue.
If you are trying to install on Linux, depending on flavor and its setup , sometimes swap is setup as as /tmp and some applications are not able to write to /tmp. In your case it does looks like its trying to write to /tmp and erroring out.
Can you try pip install cryptography
and see if its able to install cryptography part without issues?
Once that dependency is out of way, you can install pysnap so that pysnap will not try to install cryptography

How to install zeroRPC (python) on windows

I would like to try zeroRPC but couldn't install the package properly. I am using the latest python_xy distribution (python 2.7.3) under windows 7 and I must say I don't have much experience with installing new modules since the distribution is allready pretty complete.
I pulled the master zeroRPC-python from gitHub and tried to do "python setup.py install"
I had a first problem with something like "impossible to locate vcvarsall.bat". I solved it by installing mingw as explained here error: Unable to find vcvarsall.bat
Then I could run the install untill the end, but now, when I import zerorpc, I get the following ImportError (only the end of the stack):
C:\Python27\lib\site-packages\gevent-0.13.8-py2.7-win32.egg\gevent\greenlet.py in <module>()
4 import traceback
5 from gevent import core
----> 6 from gevent.hub import greenlet, getcurrent, get_hub, GreenletExit, Waiter
7 from gevent.timeout import Timeout
8
C:\Python27\lib\site-packages\gevent-0.13.8-py2.7-win32.egg\gevent\hub.py in <module>()
28
29 try:
---> 30 greenlet = __import__('greenlet').greenlet
31 except ImportError:
32 greenlet = __import_py_magic_greenlet()
ImportError: No module named greenlet
I wonder more generally if I am following the right procedure to install new packages (under windows) or if there is a simpler way (safer with dependancies) that I would be overlooking (easy_install)? I must say I am very new to this and any hints or link to the relevant documentation would be appreciated.
Thanks in advance,
Samuel
I was struggling with this question myself for a while now. The solution involves several components, and many answers out there seem to relate to different versions of those components that don't always play well together.
Here is the complete solution that worked for me, starting from an empty virtualenv:
mkvirtualenv myenv
python -m pip install --upgrade pip==6.0.8 wheel==0.24.0
pip install gevent-1.0.1-cp27-none-win32.whl pyzmq-13.1.0-cp27-none-win32.whl zerorpc==0.4.4
The first step installs wheel and upgrades pip itself to support wheel package installations. The next step installs binary wheels for gevent-1.0.1 (downloadable from this unofficial but extremely useful python windows binaries page) and pyzmq-13.1.0 (available here), and the zerorpc-0.4.4 package from source in the usual way.
Note that I hard-coded source package versions here (pip 6.0.8, wheel 0.24.0, zerorpc 0.4.4) because as I said other versions don't always follow the same build patterns. This may not be necessary and future versions may prove to work just as well together.
The final result for me:
(myenv) C:\work>pip freeze
gevent==1.0.1
greenlet==0.4.5
msgpack-python==0.4.5
pyzmq==13.1.0
wheel==0.24.0
zerorpc==0.4.4
I used a slightly different way, I am using Anaconda + Jupyter to run my python notebooks.
I used this link to zerorpc package, and installed using
conda install -c groakat zerorpc
which installed following -

Categories

Resources