I am unable to import the sqlite3 module in Python, version 3.5.0. Here's what I get:
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named '_sqlite3'
I know, I know, there are PLENTY of StackOverflow posts and support forums across the web where people complain about this problem, but none of the posted solutions have worked for me so far. Here's where I've been:
I also have Python 2.6.6 installed on this server, which is running CentOS 6.8 x86_64. I can open up the Python REPL and import sqlite3 just fine when using Python 2.6.6. I can also use sqlite3 from straight from bash and nothing seems awry.
This helpful question looked promising. I tried to re-configure and re-compile Python3.5 with the --enable-loadable-sqlite-extensions option, as user jammyWolf suggested. Nope, same error still occurs.
I've been using virtual environments like a good boy, but I have root access to this server. So, I was a bad boy and ran python3 as root without any virtualenvs activated. Still no luck. So I don't think it has anything to do with permissions.
I noticed that in the error message, it says No module named '_sqlite3'. This thread suggests that the underscore before the module name means that the module is an implementation detail, and isn't exposed in the API. ... I'm not sure what to make of this information, but there may be a hint somewhere in there.
Any ideas?
Falsetru is correct, I am going to go into a bit more detail for those not familiar (linux instructions). If you are getting this error, chances are you are using a version of python that was compiled without the correct headers. Here's a step by step guide to get it sorted. (Python 3.X.X instructions)
Install the required sqlite libraries
sudo apt-get install libsqlite3-dev
Uninstall python (I'm using python 3.6.5 as an example in this guide)
sudo apt-get remove python3.6
Download python from source
cd /tmp && wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
Unpack the archive
tar -xvf Python-3.6.5.tgz
Configure
cd Python-3.6.5 && ./configure
Make and install (and go make coffee while you're at it)
make && sudo make install
If you did everything correctly running "python3.6 -V" should give you your python version. Note you will have to rebuild any virtual environments you have as well.
One final caveat you may encounter.
zipimport.ZipImportError: can't decompress data; zlib not available
This happens if you don't have the following zlib library installed:
sudo apt-get install zlib1g-dev
Install sqlite-devel package which includes header, library that is required to build sqlite3 extension.
yum install sqlite-devel
NOTE: Python does not include sqlite3 library itself, but an extension module (wrapper).
I copied sqlite3.dll to this folder:
C:\Users\*****\Anaconda3\DLLs
It worked after two weeks trying everything else.
Related
I installed python3.8 in my Linux mint and i used this commands to make python3.8 default
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.8 2
sudo update-alternatives --config python3
sudo rm usr/bin/python3
And when ever i typed nonsense in terminal i get this error. How can i fix the problem?
Traceback (most recent call last):
File "`/usr/lib/command-not-found`", line 28, in <module>
from CommandNotFound import CommandNotFound
File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in <module>
from CommandNotFound.db.db import SqliteDatabase
File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in <module>
import apt_pkg
When you type an unknown command, some versions of Linux (including yours) try to give you suggestions for what you might have meant (or what packages you might need to install). In this case, the code for giving the suggestions is written in Python, and worked in the original version of python. In the new version, it cannot find one of its libraries, apt_pkg.
Possible solutions:
Switch back to the original version of python as the default, and explicitly use python3.8 when that's what you want. If you normally use virtualenv (or similar), you only need to specify the Python version when you create a new virtual environment, not every time.
Switching back is probably the best option.
Install the apt_pkg library for the new version of Python. That will solve the immediate problem, but likely all sorts of other system scripts are also failing, and chasing down all of them will be quite tedious, frustrating and error-prone. You're likely to miss some, where the errors are non-obvious. Unless you're very thorough, you'll have a system that works poorly.
It seems to be failing to find a database file, so you may need to reinstall this section of your python installation. Failing this, I suggest trying to reinstall your entire python installation and also try restarting your computer.
I'm working on a web app django, when I install openbabel and try to import pybel i've got an error
I'm using a venv that was activate when I did all this commands
I install openbabel like this:
sudo apt-get install python-openbabel
I also tried :
sudo apt-get install openbabel libopenbabel-dev swig
Then I did :
pip install openbabel
after that, I've tried to import pybel (after importing openbabel)
This is actuall result :
>>> import pybel
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 94, in <module>
descs = _getpluginnames("descriptors")
File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 84, in _getpluginnames
return [x.split()[0] for x in plugins]
File "/home/etudiant/QuChemPedIA/QuChemPedIAProject/venv/lib/python3.5/site-packages/pybel.py", line 84, in <listcomp>
return [x.split()[0] for x in plugins]
IndexError: list index out of range
Any help please?
As #Manu mathew said, this is a bug, but not in Python's openbabel package but rather in the openbabel C library that it wraps (provided by the openbabel apt package).
The bug is fixed in version openbabel/2.3.2+dfsg-3 that for your Ubuntu Xenial (judging by your Python version) is not available.
So you need to upgrade your distro. The fix is available since Bionic but for best results, upgrade to the latest distro release (see below for explanation).
Beside that,
Installing python-openbabel apt package is useless because it's for Python 2. A package for Python 3 would be called "python3-openbabel" but there's no such package. So you do have to install the bindings from PyPI.
Installing a Python package both globally with apt-get and into venv with pip is redundant.
If you are using an old distro, you also open yourself to possible breakage when you link a new bindings package from PyPI against an old C library on your system. If the bindings package builds against your local library, it is likely meant to support this version, but who knows how much this combination was tested.
So normally, you should prefer the apt-get version of a Python package that wraps a local C library if one is available if you are using the system Python. You can make globally installed packages available in a venv by creating it with --system-site-packages.
But since in this case, there's no apt-get version of bindings available, you have to install the bindings from PyPI. In this case, you'd better have the C library version that corresponds to the bindings' version -- i.e. probably the latest -- since that combination was clearly extensively tested.
My target host is SUSE 11 but it does not have access to the internet.
I was able to install Python 3.6.1 from source but I had to disable pip using --with-ensurepip=no
Otherwise the install failed with ModuleNotFoundError: No module named 'pyexpat'
If I try to install pip using get-pip.py I get the same error. (no suprise there)
How can I resolve this?
I'm having this same build error, but with pyenv. I'm not sure if my solution will work but hopefully it does.
I spent a good 4 hours searching, and everyone online seems to be saying that Mojave and up is missing some headers and then instructing you to manually download those headers here:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
However I think installing those headers is what actually caused the issue for me.
I don't know if it is actually the proper fix, but going to https://developer.apple.com/download/more/ and downloading/reinstalling the Command Line Tools is the only thing that worked for me.
After reinstalling the command line tools, I did not install the supposedly missing headers. And then I did not experience the build failure mentioning a missing pyexpat module.
The following steps solved this problem for me:
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
After that I installed python with:
python-build 3.6.10 ~/.runtimes/Python36
(Note that you can change the version as per your requirement)
Also, as mentioned in one of the answers, running
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
after xcode-select --install broke things for me again.
I was able to resolve the issue by following the instructions noted here:
Specifically it was the for loop:
for m in _struct binascii unicodedata _posixsubprocess math pyexpat _md5 _sha1 _sha256 _sha512 select _random _socket zlib fcntl; do
sed -i "s/^#\(${m}\)/\1/" Modules/Setup;
done
Many thanks to Warren and all who contributed to the post.
Conda gives error when I run any command with it.
Traceback (most recent call last):
File "/usr/local/bin/conda", line 7, in <module>
from conda.cli.main import main
File "/usr/local/lib/python2.7/dist-packages/conda/cli/__init__.py", line 8, in <module>
from .main import main # NOQA
File "/usr/local/lib/python2.7/dist-packages/conda/cli/main.py", line 46, in <module>
from ..base.context import context
File "/usr/local/lib/python2.7/dist-packages/conda/base/context.py", line 18, in <module>
from ..common.configuration import (Configuration, MapParameter, PrimitiveParameter,
File "/usr/local/lib/python2.7/dist-packages/conda/common/configuration.py", line 40, in <module>
from ruamel.yaml.comments import CommentedSeq, CommentedMap # pragma: no cover
ImportError: No module named ruamel.yaml.comments
The module ruamel.yaml.comments will normally be loaded from site-packages/ruamel/yaml/comments.py, and not from site-packages/ruamel_yaml/comments.py
Conda seems to have problems with properly supporting namespaces (ruamel.) which I can only attribute to not (yet) being fully pip compatible. That although "namespaces are a honking good idea", and package namespaces have been around for many years.
Assuming you can extend "conda" installations with pip you could try to do a normal install of ruamel.yaml with:
pip install ruamel_yaml==0.11.14
I would not normally recommend such an old version, but that is more likely to work in combination with the version conda uses itself internally.
The alternative would be to switch to using python and pip without conda, that way you can just use the latest version of software from PyPI.
Try pip install ruamel.yaml
It works for me.
Try conda install ruamel.yaml ... pip didnt work for me
Try sudo pip install ruamel_yaml
I went into this file:
/anaconda2/lib/python2.7/site-packages/dateparser/utils/__init__.py
edited this line:
import ruamel.yaml as yaml
to read
import ruamel_yaml as yaml
Changing the dot to an underscore worked for me.... I hope it works for you.
this worked for me:
pip install --upgrade ruamel.yaml --ignore-installed ruamel.yaml
from an answer in matsci.org
https://matsci.org/t/modulenotfounderror-no-module-named-ruamel/36183
The above answer didn't work for me. I had to do a fresh install of the core conda components as described in the conda docs here. Copy and pasted below:
Issue: My conda is broken and I want to fix it without blowing away the current installation
I am getting a conda error and want to reinstall Miniconda to fix it but when I try, it gives me the error that Miniconda (or Anaconda) is already installed and will not let me continue. I want to force the installation.
Resolution: Install Miniconda using the -f (force) option
Download and install the appropriate Miniconda for your computer operating system from the Miniconda download page using the force or -f option as shown:
bash Miniconda3-latest-MacOSX-x86_64.sh -f
NOTE: Substitute the appropriate filename and version for your
operating system.
NOTE: Be sure that you install to same install location as your
existing install so it overwrites the core conda files and does not
install a duplicate in a new folder.
Go to anaconda3\lib\site-packages\rpcq_base.py
and change line #22 :
from ruamel import yaml
to
from ruamel_yaml as yaml
This might not be a popular answer, but it finally helped me after many hours of troubleshooting:
Uninstall conda (I used this stack overflow solution) and also rm -rf miniconda3 in my home directory, fwiw.
Reinstalled conda using data camp's tutorial.
No other solutions worked for me after lots of head banging.
For python3 use
pip3 install ruamel_yaml
if pip3 not installed try at first
sudo apt install python3-pip
For me this was a conda/pip error. I'd tried to install (cwltool in my case) through pip.
It completed successfully, but then running any command gave me the error like above.
ImportError: No module named ruamel.yaml.
It turned out that the pip binary wasn't part of my conda env and was installing cwltool into a completely separate location.
To resolve the issue I completed the following:
conda activate <env I want to install cwltool into>
conda install -y pip
# Run 'rehash' now if you're using zsh to ensure you're using the right pip
pip install cwltool
cwltool -h
To add to what #user612161 has said, go to the directory of parent module (dateparser in this case) requiring ruamel.yaml:
cd anaconda2/lib/python2.7/site-packages/dateparser
and change all occurrences of ruamel.yaml into ruamel_yaml by the following command (Linux):
find . -name '*.py' | xargs sed -i 's/ruamel.yaml/ruamel_yaml/g'
The quick and easy is to ignore the previously installed version in an upgrade
pip install --ignore-installed ruamel_yaml==0.17.4
I was trying to link Bloomberg to Python
pip install --index-url=https://bcms.bloomberg.com/pip/simple blpapi
pip install xbbg
so far, so good.... then I tried to import a module from the package xbbg:
from xbbg import blp
and I was faced with an error, it couldn't find "ruamel.yaml" within the "param.py" within the xbbg module
When I dug into the folder C:/Anaconda3/Lib/site-packages I could see that there was a folder there called ruamel_yaml so I went back to the param.py file and edited ruamel.yaml to be ruamel_yaml as suggested in other posts.
"from xbbg import blp" now worked and I'm able to take data directly from Bloomberg into Python now. Problem solved.
I have a feeling that this issue is being caused by downloading different versions at different times as I've found the learning curve to get setup on Python difficult with many false starts. I was tearing my hair out a bit because I just got Python up and running linked to Bloomberg on my work pc but when I tried to link Bloomberg up to Python on my laptop it kept getting stuck with the "ruamel" issue. The version of Python on my laptop is much older than the version on my work pc. What makes me think that its a version issue is that I did not have to edit ruamel.yaml to be ruamel_yaml in order for me to link Python and BB.
These are just ideas, I'm too inexperienced at this stage to offer much more than to share what happened.
I need to install PIL (python imaging library) on my Ubunto10.4-32bit (EDIT:64bit) machine on my python2.5.4-32bit.
This question is also relevant to any other source package I guess (among those that I need are RPyC,psyco and numpy).
I downloaded the source-code since I can't find any neat package to do the job and did
a sudo python2.5 setup.py install.
output:
Could not find platform dependent libraries <exec_prefix>
Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>]
Traceback (most recent call last):
File "setup.py", line 9, in <module>
import glob, os, re, struct, string, sys
File "/usr/lib/python2.5/struct.py", line 30, in <module>
from _struct import Struct, error
ImportError: No module named _struct
but
echo $PYTHONHOME
/usr
Well, in the file struct.py theres the line from _struct import Struct, error
This is part of the python source code itself so I really wonder whats wrong with the python installation, since the code fails to import the module.
I installed py2.5.4 by doing:
./configure --prefix=/usr
make altinstall
(using make altinstall since I need py26 as default python interpreter)
EDIT: This issue might have risen from mistakenly using a 64bit platform :) and 32bit python2.5 . So anyhow problem solved by reducing unnecessary complexities - switching to 32bit machine and porting app to python 2.6.
In short:
Try using the Ubuntu repository first. If the package isn't there, use easy_install. If all fails, download the package directly to your source folder.
Ubuntu repository (the apt-get approach)
Ubuntu (10.04 and newer) has most mainstream packages are available with apt-get. The naming convention is python-NAME, e.g. python-imaging or python-scipy.
This is the best way to go, since the native package manager will handle any dependencies and updates issues.
Run apt-cache search python | grep "^python-" | less to see a list of packages available for your system (I have over 1,200 in my 10.04 machine).
Setuptools
For packages that are not part of the Ubuntu repository, you can use the python easy-install tool. First, install the setup tool:
sudo apt-get install python-setuptools
And you can install any Python package, e.g. colorworld, using easy-install:
sudo easy_install colorworld
This gives you some degree of protection (e.g., handles dependencies) but updates are generally manual, and it's a real pain to reinstall all these packages in a new computer.
Manual download
You can always download the source code to some directory and add it to your PYTHONPATH. It's the best approach when you just need to evaluate a package or apply some quick-and-dirty solution.
sudo aptitude install python-imaging
This will install PIL library.
sudo aptitude install python-imaging
That will install PIL. But I'm not really sure how to help with your other packages. Maybe try searching for them in synaptic.