So I'm trying to use Paramiko on Ubuntu with Python 2.7, but import paramiko causes this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named paramiko
The other questions on this site don't help me since I'm new to Ubuntu.
Here are some important commands that I ran to check stuff:
sudo pip install paramiko
pip install paramiko
sudo apt-get install python-paramiko
Paramiko did "install". These are the only commands I used to "install" paramiko. I'm new to Ubuntu, so if I need to run more commands, lay them on me.
which python
/usr/local/bin/python
python -c "from pprint import pprint; import sys; pprint(sys.path);"
['',
'/usr/local/lib/python27.zip',
'/usr/local/lib/python2.7',
'/usr/local/lib/python2.7/plat-linux2',
'/usr/local/lib/python2.7/lib-tk',
'/usr/local/lib/python2.7/lib-old',
'/usr/local/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/site-packages']
In the python interpreter, I ran help("modules") and Paramiko is not in the list.
two paramiko folders are located in usr/local/lib/python2.7/dist-packages.
Short version: You're mixing Ubuntu's packaged version of Python (/usr/bin/python) and a locally built and installed version (/usr/local/bin/python).
Long version:
You used apt-get install python-paramiko to install Ubuntu's official Paramiko package to /usr/lib/python2.7/dist-packages.
You used (I assume) Ubuntu's version of pip, which installs to /usr/local/lib/python2.7/dist-packages. (See here.)
You used a locally built version of Python, and because it's locally built, it uses /usr/local/lib/python2.7 instead of /usr/lib/python2.7, and because it doesn't have Debian/Ubuntu customizations, it doesn't check use dist-packages.
Solution: You should be able to add /usr/local/lib/python2.7/dist-packages to your /usr/local/bin/python's sys.path, but since you're using Ubuntu, it's easiest to let Ubuntu do the work for you:
Use /usr/bin/python instead of a local version.
Use Ubuntu's packages wherever possible (i.e., use apt-get instead of pip).
Use virtualenv for the rest (to keep a clean separation between Ubuntu-packaged and personally installed modules).
I'd go so far as to uninstall the local version of Python and delete /usr/local/lib/python2.7, to ensure that no further mismatches occur. If you don't want to be that drastic, then you can edit your $PATH to put /usr/bin before /usr/local/bin to run the system version of Python by default.
Try downloading the zip file from https://github.com/paramiko/paramiko and running this command in the unzipped directory :
python setup.py install
There are two others methodes for add modules in python :
The first :
Download the package.
Create directory and paste the package in it.
Tap in the terminal :
export PYTHONPATH=$PYTHONPATH:path_of_package
The second :
open python interpreter:
import sys
sys.path.insert(0, "path_of_package")
Try installing only through commands.
Download paramiko package from git using this command: git clone https://github.com/paramiko/paramiko.git
Go to unzipped directory and run export PYTHONPATH=$PYTHONPATH:<path_to_paramiko>
If you find libffi package not found then run this command: sudo apt-get install libffi6 libffi-dev and If you haven't properly installed the header files and static libraries for python dev then run this command: sudo apt-get install python-dev
Enjoy :)
Also, mind the version of python, if the error was reported by python3, then install python3's paramiko.
If you're using Python 3, type the below command
$ sudo -H pip3 install paramiko --ignore-installed
try type pi then tap, this give you this
:$ pi
pic piconv pidstat pinentry-curses ping6
pip3 pivot_root
pic2graph pidof pinentry ping pinky
pip3.6
then you type in whereis pip3
$ whereis pip3
pip3: /usr/local/bin/pip3.6 /usr/local/bin/pip3
xg#xx-ppmaster:/xg/scripts/pyth
$ sudo /usr/local/bin/pip3 install paramiko
This should let you install paramiko
more on python installation
https://danieleriksson.net/2017/02/08/how-to-install-latest-python-on-centos/
Related
I feel like this has to have been asked and solved already, but I couldn't find a solution that works for me. I pip3'd a python library, and verify it is indeed on my system.
pi#raspberrypi:~/Desktop $ pip3 install pyftpdlib
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: pyftpdlib in /home/pi/.local/lib/python3.7/site-packages (1.5.6)
Then I try to import it but raspi cant find it...
pi#raspberrypi:~/Desktop $ sudo python3 FTPserver2.py
Traceback (most recent call last):
File "FTPserver2.py", line 1, in <module>
import pyftpdlib
ModuleNotFoundError: No module named 'pyftpdlib'
Huh?
When you run pip3 install without sudo, the package gets installed under /home/pi/.local/lib/python3.7/site-packages which is a user-specific location and packages installed there will not be accessible system-wide.
Then you run sudo python3 which makes you execute python3 as the root user which is a different user.
Below I assume you do need to run the command with sudo. If you're not sure, try dropping the sudo - then the import should work (but maybe other stuff will not - I don't know what's in your script).
One method of installing a package for use by root would be to do sudo pip3 install pyftpdlib but this not recommended as it could break the Python installation used by the OS (some packages could have to be updated in order to be compatible with pyftpdlib, but they could then become incompatible with other stuff, and then you're in a lot of trouble).
It is better to use a virtual environment. For example:
# create the virtual environment
$ python3 -m venv env-ftp
# install the package into it
$ env-ftp/bin/python -m pip install pyftpdlib
# run a script using the Python installation contained within the virtual environment
$ sudo env-ftp/bin/python -m Desktop/FTPserver2.py
You could also choose to source env-ftp/bin/activate in order to temporarily switch to using python and pip specific to this environment until you deactivate.
Virtual environments are useful for creating isolated Python installations with their own separate sets of packages, which allows you e.g. to simultaneously use applications that have incompatible sets of dependencies (suppose 1 application requires requests==2.22.0 and another one requires requests<=2.21.0 and won't work with requests==2.22.0).
Can you try running this in the command line without errors?:
python3 -c "import pyftpdlib"
If this returns no error, that means your python interpreter is different. Make sure you are not running different python versions and/or have created different images and have not used sudo privileges to install packages.
As you can see, the pip3 has installed it in the site packages of /home/pi/.local/lib/python3.7/
Run this in command line
python3 -c "import site; print(site.getsitepackages())"
and check if it returns the same path as pip.
PS: It is always recommended to run pip3 install --user instead of sudo pip3 install.
I need to get pip3 running on my Mac terminal for a project. I have python3 installed, and I can run it, but when I try to run pip3 freeze, it says my command is not found.
I thought it would be automatically installed when I installed Python3. I tried to sudo install it, but it still didn't do anything. What can I do?
Besides brew install pip3, in case brew is not installed on your Mac, you can install pip3 via get_pip.py which can be found here. Assuming that python3 is already installed, cd to the directory where you saved get_pip.py and run the file with python3 get_pip.py. This should get pip3 installed on your machine.
On my MacBook Pro (10.13.5), which pip3 shows that it is located at /opt/local/bin/pip3 but it is a symlink to /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3.
This is the location of python3 if you installed it via MacPorts. If you installed it with HomeBrew, then it would be /usr/local/Cellar/python/3.7.0/bin/pip3 (again, version might vary).
Finding pip3
What I would do if I were you is first find out where your pip3 actually is by either using locate or trying to manually find it by typing (Change 3.6 to whatever version you're on.) either:
$ /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3 --version
or:
$ /usr/local/Cellar/python/3.7.0/bin/pip3 --version
You should see something like:
pip 9.0.3 from /opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (python 3.6)
Otherwise, use locate:
$ locate pip3
As a last resort, the slow find can also be useful:
$ sudo find / -name pip3
Build a Symlink
Then, make a symbolic link to that file in a path that is in your $PATH (again, ensure you replace the first path with the path to your actual pip3):
$ sudo ln -s /opt/local/Library/Frameworks/Python.framework/Versions/3.6/bin/pip3 /opt/local/bin/pip3
Assuming you are using Python 3.4 or later in which pip is included by default, try the following command:
python3 -m pip freeze
When you use the -m command-line flag, python will search sys.path for the named module and execute its contents as the __main__ module. (more here)
This solution will allow you to use pip by python3 -m pip, but in order to use pip3 directly you can:
Install it via Homebrew:
brew install pip3
Install it with get-pip.py:
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
You could try brew install pip3. Or check where pip is installed, that might point to Python 3's version.
I'm running Python 3.5 (on Windows) and I have installed python-ldap from https://pypi.python.org/pypi/python-ldap/
I also tried using ldap3 but I keep getting an error saying
"ImportError: No module named 'ldap'
I looked around and saw some people saying there's no python-ldap for 3.5 so I installed 2.6 still getting the same error.
Is there a way to import ldap and make it work for Python 3.5?
Try the command below:
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap
Open a command line(cmd, powershell, git bash)
Check you python version
$ pyhton --version
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the library according with your python version and windows system
And install it on a command line using
pip install file_downloaded.whl
For example:
If you have python 3.5x and windows x64,
download the file python_ldap‑3.2.0‑cp35‑cp35m‑win_amd64.whl
pip install python_ldap‑3.2.0‑cp35‑cp35m‑win_amd64.whl
I'm running Apache Airflow on an Amazon EC2-Instance and I was getting "ImportError: No module named 'ldap3'. I used these two sites https://www.python-ldap.org/en/latest/installing.html and http://ldap3.readthedocs.io/installation.html to run the commands sudo python -m pip install python-ldap and sudo pip install ldap3 but my pip wasn't working for the last command so after some investigation I found out in my /usr/bin/ directory I had pip, pip-2.7, pip-3.6, and pip-python so I changed the command to pip-3.6 install ldap3 and then everything worked! Hope this helps someone.
I tried multiple approaches but finally, PyPI official documentation fixed this.
I was trying to execute on VS Code and did pip3 install python-ldap, but it didn't solve the issue. So I did the below from VS Code
# %% - This runs the below code as a Jupyter notebook cell
!pip3 install python-ldap
Now, I am able to import ldap and use it
Inside you folder, you can use virtualenv for python 3, example:
/opt/python-ldap-test
virtualenv -p /usr/bin/python3.5 venv
source venv/bin/activate
and then
pip install ldap3
It's extremely complicated to make things from 2.X to work in 3.X. Have you tried using it in a separate, 2.X only script and using it from there? It's not so unusual to combine python 2.X with 3.X in that manner or so I've heard.
I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:
File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
Looking at the Python install, it gives the same error:
Python 2.5.2 (r252:60911, May 12 2009, 07:46:31)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
>>>
Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included. Do I need to reinstall Python, or is there another way to get this module up and running?
It seems your makefile didn't include the appropriate .so file. You can correct this problem with the steps below:
Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install
Note
The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. If you run this command on your workstation, you'll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall.
I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I've installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.
I had the same problem with Python 3.5 on Ubuntu while using pyenv.
If you're installing the python using pyenv, it's listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version with
pyenv install <python-version>
Then recreate virtualenv if needed.
my python is build from source, the cause is missing options when exec configure
python version:3.7.4
./configure --enable-loadable-sqlite-extensions --enable-optimizations
make
make install
fixed
This is what I did to get it to work.
I am using pythonbrew(which is using pip) with python 2.7.5 installed.
I first did what Zubair(above) said and ran this command:
sudo apt-get install libsqlite3-dev
Then I ran this command:
pip install pysqlite
This fixed the database problem and I got confirmation of this when I ran:
python manager.py syncdb
Install the sqlite-devel package:
yum install sqlite-devel -y
Recompile python from the source:
./configure
make
make altinstall
I found lots of people meet this problem because the Multi-version Python,
on my own vps (cent os 7 x64), I solved it in this way:
Find the file "_sqlite3.so"
find / -name _sqlite3.so
out: /usr/lib64/python2.7/lib-dynload/_sqlite3.so
Find the dir of python Standard library you want to use,
for me /usr/local/lib/python3.6/lib-dynload
Copy the file:
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
Finally, everything will be ok.
For Python 3.7.8 with Redhat 7 or Centos 7.
Install sqlite-devel
$ yum install sqlite-devel
Compile and install Python3 with sqllite extensions
$ ./configure --enable-optimizations --enable-loadable-sqlite-extensions
$ make install
My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so. Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.
Try the following:
find /usr/local -name _sqlite3.so
If the file isn't found, something may be wrong with your Python installation. If it is, make sure the path it's installed to is in the Python path. In the Python shell,
import sys
print sys.path
In my case, /usr/lib/python2.5/lib-dynload is in the list, so it's able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.
I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. Came across similar problems to this thread. I mamaged to fix it by:
Adjusting the setup.py file to include the correct sqlite dev path. Code snippet from setup.py:
def sqlite_incdir:
sqlite_dirs_to_check = [
os.path.join(sqlite_incdir, '..', 'lib64'),
os.path.join(sqlite_incdir, '..', 'lib'),
os.path.join(sqlite_incdir, '..', '..', 'lib64'),
os.path.join(sqlite_incdir, '..', '..', 'lib'),
'/usr/lib/x86_64-linux-gnu/'
]
With the bit that I added being '/usr/lib/x86_64-linux-gnu/'.
After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly :P ), but after running make install, sqlite3 still did not import with the same "ImportError: No module named _sqlite3" whe running "import sqlite3".
So, the library was compiled, but not moved to the correct installation path, so I copied the .so file (cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).
Voila! SQLite3 support now works.
This worked for me in Redhat Centos 6.5:
yum install sqlite-devel
pip install pysqlite
sqlite3 ships with Python. I also had the same problem, I just uninstalled python3.6 and installed it again.
Uninstall existing python:
sudo apt-get remove --purge python3.6
Install python3.6:
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall
Is the python-pysqlite2 package installed?
sudo apt-get install python-pysqlite2
Checking your settings.py file.
Did you not just write "sqlite" instead of "sqlite3" for the database engine?
Putting answer for anyone who lands on this page searching for a solution for Windows OS:
You have to install pysqlite3 or db-sqlite3 if not already installed. you can use following to install.
pip install pysqlite3
pip install db-sqlite3
For me the issue was with DLL file of sqlite3.
Solution:
I took DLL file from sqlite site. This might vary based on your
version of python installation.
I pasted it in the DLL directory of
the env. for me it was "C:\Anaconda\Lib\DLLs", but check for yours.
I have the problem in FreeBSD 8.1:
- No module named _sqlite3 -
It is solved by stand the port ----------
/usr/ports/databases/py-sqlite3
after this one can see:
OK ----------
'>>>' import sqlite3 -----
'>>>' sqlite3.apilevel -----
'2.0'
you must be in centos or redhat and compile python yourself,
it is python‘s bug
do this in your python source code dir and do this below
curl -sk https://gist.github.com/msabramo/2727063/raw/59ea097a1f4c6f114c32f7743308a061698b17fd/gistfile1.diff | patch -p1
I was disappointed this issue still exist till today. As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it. The way I had to resolve it in my case is as follow:
Install SQLite3 from scratch with the proper prefix
Make clean my Python Installation
Run Make install to reinstall Python
As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension. I have end up capturing the steps I used to fix the issue and put it in a separate blog post at:
http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html
I hope this helpful, as while the tips above had helped me get to a solution, I had to combine few of them and modify them a bit.
i got the same problem, nothing worked for me from the above ans
but now i fixed it by
just remove python.pip and sqlite3 and reinstall
sudo apt-get remove python.pip
sudo apt-get remove sqlite3
now install it again
sudo apt-get install python.pip
sudo apt-get install sqlite3
in my case while installing sqlite3 again it showed some error
then i typed
sqlite3
on terminal to check if it was removed or not and it started unpacking it
once the sqlite3 is installed
fireup terminal and write
sqlite3
database.db (to create a database)
i'm sure this will definately help you
Try installing sqlite like this if you are using FreeBSD.
pkg install py27-sqlite3-2.7.10_6
I had the same problem after installing Python 3.8.11 using asdf
To fix the issue:
I had to install libsqlite3-dev
sudo apt-get install libsqlite3-dev
Then uninstall Python via asdf
asdf uninstall python 3.8.11
And install Python again via asdf
asdf install python 3.8.11
The following worked for Python 3.9 with a virtual environment:
Install the sqlite3 library.
sudo apt-get install libsqlite3-dev
Activate the Python virtual environment.
source env/bin/activate
Copy the sqlite3 file into the Python virtual environment and rename it to support Python 3.9.
cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages
mv ./env/lib/python3.9/site-packages/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages/_sqlite3.cpython-39-x86_64-linux-gnu.so
Note, we're renaming 38 to 39 in the file name to support Python 3.9.
Download sqlite3:
wget http://www.sqlite.org/2016/sqlite-autoconf-3150000.tar.gz
Follow these steps to install:
$tar xvfz sqlite-autoconf-3071502.tar.gz
$cd sqlite-autoconf-3071502
$./configure --prefix=/usr/local
$make install
I faced this issue with multiple python dependent package while setup in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.
Error I got:
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I resolved it by --enable-loadable-sqlite-extensions=yes
1.) First find your python or python version you used for creating virtual env. I have used python3.8
e.g
$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config python
$ cd /usr/bin
$ls
python3.8
python3.8-config
Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version
ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes
OR
ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions
Now, create your virtual env using that python version
e.g
Go the folder where you want to create the virtual env
$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate
Its done, now you can install packages
I ran into this same problem on a NetBSD server. A missing .so file needed to be installed using pkgin. To identify what package to install, I ran
pkgin search sqlite
which had lots of results, including
...
py38-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py38-apsw-3.37.0nb2 Python wrapper for SQLite
py38-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py38-sqlite3-3.8.13nb22 Built-in sqlite support for Python 2.5 and up
py39-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py39-apsw-3.37.0nb2 Python wrapper for SQLite
py39-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py39-sqlite3-3.9.13nb22 Built-in sqlite support for Python 2.5 and up
...
(and other python versions as well). I'm using python 3.9, so py39-sqlite3-3.9.13nb22 was the correct choice in my case. Running
sudo pkgin install py39-sqlite3-3.9.13nb22
fixed the issue for me.
You need to install pysqlite in your python environment:
$ pip install pysqlite
Try copying _sqlite3.so so that Python can find it.
It should be as simple as:
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/
Trust me, try it.
I am trying to run a Django app on my VPS running Debian 5. When I run a demo app, it comes back with this error:
File "/usr/local/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/usr/local/lib/python2.5/site-packages/django/db/backends/sqlite3/base.py", line 30, in <module>
raise ImproperlyConfigured, "Error loading %s: %s" % (module, exc)
ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named _sqlite3
Looking at the Python install, it gives the same error:
Python 2.5.2 (r252:60911, May 12 2009, 07:46:31)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.5/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/usr/local/lib/python2.5/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
>>>
Reading on the web, I learn that Python 2.5 should come with all the necessary SQLite wrappers included. Do I need to reinstall Python, or is there another way to get this module up and running?
It seems your makefile didn't include the appropriate .so file. You can correct this problem with the steps below:
Install sqlite-devel (or libsqlite3-dev on some Debian-based systems)
Re-configure and re-compiled Python with ./configure --enable-loadable-sqlite-extensions && make && sudo make install
Note
The sudo make install part will set that python version to be the system-wide standard, which can have unforseen consequences. If you run this command on your workstation, you'll probably want to have it installed alongside the existing python, which can be done with sudo make altinstall.
I had the same problem (building python2.5 from source on Ubuntu Lucid), and import sqlite3 threw this same exception. I've installed libsqlite3-dev from the package manager, recompiled python2.5, and then the import worked.
I had the same problem with Python 3.5 on Ubuntu while using pyenv.
If you're installing the python using pyenv, it's listed as one of the common build problems. To solve it, remove the installed python version, install the requirements (for this particular case libsqlite3-dev), then reinstall the python version with
pyenv install <python-version>
Then recreate virtualenv if needed.
my python is build from source, the cause is missing options when exec configure
python version:3.7.4
./configure --enable-loadable-sqlite-extensions --enable-optimizations
make
make install
fixed
This is what I did to get it to work.
I am using pythonbrew(which is using pip) with python 2.7.5 installed.
I first did what Zubair(above) said and ran this command:
sudo apt-get install libsqlite3-dev
Then I ran this command:
pip install pysqlite
This fixed the database problem and I got confirmation of this when I ran:
python manager.py syncdb
Install the sqlite-devel package:
yum install sqlite-devel -y
Recompile python from the source:
./configure
make
make altinstall
I found lots of people meet this problem because the Multi-version Python,
on my own vps (cent os 7 x64), I solved it in this way:
Find the file "_sqlite3.so"
find / -name _sqlite3.so
out: /usr/lib64/python2.7/lib-dynload/_sqlite3.so
Find the dir of python Standard library you want to use,
for me /usr/local/lib/python3.6/lib-dynload
Copy the file:
cp /usr/lib64/python2.7/lib-dynload/_sqlite3.so /usr/local/lib/python3.6/lib-dynload
Finally, everything will be ok.
For Python 3.7.8 with Redhat 7 or Centos 7.
Install sqlite-devel
$ yum install sqlite-devel
Compile and install Python3 with sqllite extensions
$ ./configure --enable-optimizations --enable-loadable-sqlite-extensions
$ make install
My _sqlite3.so is in /usr/lib/python2.5/lib-dynload/_sqlite3.so. Judging from your paths, you should have the file /usr/local/lib/python2.5/lib-dynload/_sqlite3.so.
Try the following:
find /usr/local -name _sqlite3.so
If the file isn't found, something may be wrong with your Python installation. If it is, make sure the path it's installed to is in the Python path. In the Python shell,
import sys
print sys.path
In my case, /usr/lib/python2.5/lib-dynload is in the list, so it's able to find /usr/lib/python2.5/lib-dynload/_sqlite3.so.
I recently tried installing python 2.6.7 on my Ubuntu 11.04 desktop for some dev work. Came across similar problems to this thread. I mamaged to fix it by:
Adjusting the setup.py file to include the correct sqlite dev path. Code snippet from setup.py:
def sqlite_incdir:
sqlite_dirs_to_check = [
os.path.join(sqlite_incdir, '..', 'lib64'),
os.path.join(sqlite_incdir, '..', 'lib'),
os.path.join(sqlite_incdir, '..', '..', 'lib64'),
os.path.join(sqlite_incdir, '..', '..', 'lib'),
'/usr/lib/x86_64-linux-gnu/'
]
With the bit that I added being '/usr/lib/x86_64-linux-gnu/'.
After running make I did not get any warnings saying the sqlite support was not built (i.e., it built correctly :P ), but after running make install, sqlite3 still did not import with the same "ImportError: No module named _sqlite3" whe running "import sqlite3".
So, the library was compiled, but not moved to the correct installation path, so I copied the .so file (cp /usr/src/python/Python-2.6.7/build/lib.linux-x86_64-2.6/_sqlite3.so /usr/local/python-2.6.7/lib/python2.6/sqlite3/ — these are my build paths, you will probably need to adjust them to your setup).
Voila! SQLite3 support now works.
This worked for me in Redhat Centos 6.5:
yum install sqlite-devel
pip install pysqlite
sqlite3 ships with Python. I also had the same problem, I just uninstalled python3.6 and installed it again.
Uninstall existing python:
sudo apt-get remove --purge python3.6
Install python3.6:
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
tar xvf Python-3.6.0.tar.xz
cd Python-3.6.0/
./configure
sudo make altinstall
Is the python-pysqlite2 package installed?
sudo apt-get install python-pysqlite2
Checking your settings.py file.
Did you not just write "sqlite" instead of "sqlite3" for the database engine?
Putting answer for anyone who lands on this page searching for a solution for Windows OS:
You have to install pysqlite3 or db-sqlite3 if not already installed. you can use following to install.
pip install pysqlite3
pip install db-sqlite3
For me the issue was with DLL file of sqlite3.
Solution:
I took DLL file from sqlite site. This might vary based on your
version of python installation.
I pasted it in the DLL directory of
the env. for me it was "C:\Anaconda\Lib\DLLs", but check for yours.
I have the problem in FreeBSD 8.1:
- No module named _sqlite3 -
It is solved by stand the port ----------
/usr/ports/databases/py-sqlite3
after this one can see:
OK ----------
'>>>' import sqlite3 -----
'>>>' sqlite3.apilevel -----
'2.0'
you must be in centos or redhat and compile python yourself,
it is python‘s bug
do this in your python source code dir and do this below
curl -sk https://gist.github.com/msabramo/2727063/raw/59ea097a1f4c6f114c32f7743308a061698b17fd/gistfile1.diff | patch -p1
I was disappointed this issue still exist till today. As I have recently been trying to install vCD CLI on CentOS 8.1 and I was welcomed with the same error when tried to run it. The way I had to resolve it in my case is as follow:
Install SQLite3 from scratch with the proper prefix
Make clean my Python Installation
Run Make install to reinstall Python
As I have been doing this to create a different blogpost about how to install vCD CLI and VMware Container Service Extension. I have end up capturing the steps I used to fix the issue and put it in a separate blog post at:
http://www.virtualizationteam.com/cloud/running-vcd-cli-fail-with-the-following-error-modulenotfounderror-no-module-named-_sqlite3.html
I hope this helpful, as while the tips above had helped me get to a solution, I had to combine few of them and modify them a bit.
i got the same problem, nothing worked for me from the above ans
but now i fixed it by
just remove python.pip and sqlite3 and reinstall
sudo apt-get remove python.pip
sudo apt-get remove sqlite3
now install it again
sudo apt-get install python.pip
sudo apt-get install sqlite3
in my case while installing sqlite3 again it showed some error
then i typed
sqlite3
on terminal to check if it was removed or not and it started unpacking it
once the sqlite3 is installed
fireup terminal and write
sqlite3
database.db (to create a database)
i'm sure this will definately help you
Try installing sqlite like this if you are using FreeBSD.
pkg install py27-sqlite3-2.7.10_6
I had the same problem after installing Python 3.8.11 using asdf
To fix the issue:
I had to install libsqlite3-dev
sudo apt-get install libsqlite3-dev
Then uninstall Python via asdf
asdf uninstall python 3.8.11
And install Python again via asdf
asdf install python 3.8.11
The following worked for Python 3.9 with a virtual environment:
Install the sqlite3 library.
sudo apt-get install libsqlite3-dev
Activate the Python virtual environment.
source env/bin/activate
Copy the sqlite3 file into the Python virtual environment and rename it to support Python 3.9.
cp /usr/lib/python3.8/lib-dynload/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages
mv ./env/lib/python3.9/site-packages/_sqlite3.cpython-38-x86_64-linux-gnu.so ./env/lib/python3.9/site-packages/_sqlite3.cpython-39-x86_64-linux-gnu.so
Note, we're renaming 38 to 39 in the file name to support Python 3.9.
Download sqlite3:
wget http://www.sqlite.org/2016/sqlite-autoconf-3150000.tar.gz
Follow these steps to install:
$tar xvfz sqlite-autoconf-3071502.tar.gz
$cd sqlite-autoconf-3071502
$./configure --prefix=/usr/local
$make install
I faced this issue with multiple python dependent package while setup in python virtual enironment in Ubuntu.It is because of sqlite binding for our python.
Error I got:
from pysqlite2 import dbapi2 as sqlite3
ModuleNotFoundError: No module named 'pysqlite2'
I resolved it by --enable-loadable-sqlite-extensions=yes
1.) First find your python or python version you used for creating virtual env. I have used python3.8
e.g
$ whereis python
python: /usr/bin/python3.6m /usr/bin/python /usr/bin/python3.8 /usr/bin/python2.7-config /usr/bin/python3.8-config python
$ cd /usr/bin
$ls
python3.8
python3.8-config
Note: there will be many package check for pytho. you will find configure file for each python version, now use specific python version
ox:/usr/bin$ ./python3.8-config --enable-loadable-sqlite-extensions=yes
OR
ox:/usr/bin$ ./python3.8-config --enable-optimizations --enable-loadable-sqlite-extensions
Now, create your virtual env using that python version
e.g
Go the folder where you want to create the virtual env
$ python3.8 -m venv mlwen_jup_env
$ source mlwen_jup_env/bin/activate
Its done, now you can install packages
I ran into this same problem on a NetBSD server. A missing .so file needed to be installed using pkgin. To identify what package to install, I ran
pkgin search sqlite
which had lots of results, including
...
py38-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py38-apsw-3.37.0nb2 Python wrapper for SQLite
py38-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py38-sqlite3-3.8.13nb22 Built-in sqlite support for Python 2.5 and up
py39-aiosqlite-0.17.0nb1 Async bridge to the standard sqlite3 module
py39-apsw-3.37.0nb2 Python wrapper for SQLite
py39-peewee-3.15.0 Small, expressive ORM for PostgreSQL, MySQL and SQLite
py39-sqlite3-3.9.13nb22 Built-in sqlite support for Python 2.5 and up
...
(and other python versions as well). I'm using python 3.9, so py39-sqlite3-3.9.13nb22 was the correct choice in my case. Running
sudo pkgin install py39-sqlite3-3.9.13nb22
fixed the issue for me.
You need to install pysqlite in your python environment:
$ pip install pysqlite
Try copying _sqlite3.so so that Python can find it.
It should be as simple as:
cp /usr/lib64/python2.6/lib-dynload/_sqlite3.so /usr/local/lib/python2.7/
Trust me, try it.