I installed Python3.6 on ubuntu16.04 and installed sqlite3. When in python2, I can import sqlite successfully, but in python3 I got an import error. I tried many methods from Google, but it still doesn't work. I want to know how to solve it.
Python 3.6.0 (default, Mar 13 2017, 06:38:19)
[GCC 5.4.0 20160609] on linux
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/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
sqlite3 will comes with python itself. I also get the same problem i just uninstalled the python3.6 and installed again.
uninstall existing python:
sudo apt-get remove --purge python3.6
Install python3.6:
sudo apt install -y \
build-essential \
checkinstall
sudo apt install -y \
libreadline-gplv2-dev \
libncursesw5-dev \
libssl-dev \
libsqlite3-dev \
tk-dev \
libgdbm-dev \
libc6-dev \
libbz2-dev
PYTHON_VERSION=3.6.0
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
tar xvf Python-${PYTHON_VERSION}.tar.xz
cd Python-${PYTHON_VERSION}/
./configure
sudo make altinstall
It works!
You can install python3 and sqlite by yourself.
try this.
Or you can try it as follows,
1. install sqlite3
$ wget https://www.sqlite.org/2017/sqlite-autoconf-3170000.tar.gz --no-check-certificate
$ tar zxvf sqlite-autoconf-3170000.tar.gz
$ cd sqlite-autoconf-3170000
$ ./configure --prefix=/usr/local/sqlite3 --disable-static --enable-fts5 --enable-json1 CFLAGS="-g -O2 -DSQLITE_ENABLE_FTS3=1 -DSQLITE_ENABLE_FTS4=1 -DSQLITE_ENABLE_RTREE=1"
2. install python3.6
$ cd Python-3.6.0
$ LD_RUN_PATH=/usr/local/sqlite3/lib ./configure --prefix=/usr/local/python3.6 LDFLAGS="-L/usr/local/sqlite3/lib" CPPFLAGS="-I /usr/local/sqlite3/include"
$ LD_RUN_PATH=/usr/local/sqlite3/lib make
$ LD_RUN_PATH=/usr/local/sqlite3/lib make install
Related
There is no problem with all compilation
mkdir pyqt
cd pyqt/
wget https://www.riverbankcomputing.com/static/Downloads/sip/4.19.25/sip-4.19.25.tar.gz
wget https://pypi.tuna.tsinghua.edu.cn/packages/28/6c/640e3f5c734c296a7193079a86842a789edb7988dca39eab44579088a1d1/PyQt5-5.15.2.tar.gz
tar zxvf sip-4.19.25.tar.gz
cd ./sip-4.19.25
sudo python3 configure.py --sip-module PyQt5.sip
sudo make
sudo make install
cd..
tar zxvf PyQt5-5.15.2.tar.gz
cd ./PyQt5-5.15.2
sudo python3 configure.py
Do you accept the terms of the license? yes
sudo make -j4
sudo make install
I compiled, but there was a problem with the import
>>> from QtSql import QSqlQuery
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: /usr/lib/python3/dist-packages/PyQt5/QtCore.so: undefined symbol: sipTypeDef_QtCore_QAbstractItemModel
I'm trying to build the pyqtdeploy-sysroot containing Qt5 and PyQt5 for the current machine (x86_64 system).
I tried Qt5 versions 5.15.0, 5.15.1 or 5.15.2 on a Fedora 30 (tried 31 and 32 as well as Debian 10 and Ubuntu 18.04, too) system using pyqtdeploy 3.0, 3.1 and 3.1.1.
On all systems I've installed all build dependencies I can think of:
python python3 python3-pip libssl-dev zlib1g-dev pyqt5-dev libqt5x11extras5-dev libgles2-mesa-dev
I event tried installing *x11*-dev and *gl*-dev (-devel respectively) :)
I always run into the following problem:
Running 'sip-install --qmake /home/frans/_HOME/2011_pyqt/docker_home/demo/sysroot-linux-64/Qt/bin/qmake --no-distinfo --concatenate 2 --no-docstrings --verbose'.
Querying qmake about your Qt installation...
/home/frans/_HOME/2011_pyqt/docker_home/demo/sysroot-linux-64/Qt/bin/qmake -query
This is the GPL version of PyQt 5.15.0 (licensed under the GNU General Public License) for Python 3.7.7 on linux.
Found the license file 'pyqt-gpl.sip'.
These bindings will be built: QtCore, QtNetwork, QtGui, QtWidgets, QtX11Extras.
Generating the QtCore bindings...
Generating the QtNetwork bindings...
Generating the QtGui bindings...
Generating the QtWidgets bindings...
Generating the QtX11Extras bindings...
Generating the .pro file for the QtCore module...
Generating the .pro file for the QtNetwork module...
Generating the .pro file for the QtGui module...
Generating the .pro file for the QtWidgets module...
Generating the .pro file for the QtX11Extras module...
Generating the top-level .pro file...
Generating the Makefiles...
/home/frans/_HOME/2011_pyqt/docker_home/demo/sysroot-linux-64/Qt/bin/qmake -recursive PyQt5.pro
sip-install: '/home/frans/_HOME/2011_pyqt/docker_home/demo/sysroot-linux-64/Qt/bin/qmake -recursive PyQt5.pro' failed returning 3
Info: creating stash file /tmp/tmp1_ng3eyh/.qmake.stash
Reading /tmp/tmp1_ng3eyh/QtCore/QtCore.pro
Reading /tmp/tmp1_ng3eyh/QtNetwork/QtNetwork.pro
Reading /tmp/tmp1_ng3eyh/QtGui/QtGui.pro
Reading /tmp/tmp1_ng3eyh/QtWidgets/QtWidgets.pro
Reading /tmp/tmp1_ng3eyh/QtX11Extras/QtX11Extras.pro
Project ERROR: Unknown module(s) in QT: x11extras
pyqtdeploy-sysroot: execution of 'sip-install' failed: returned exit code 1
I'm trying basically the same thing as this guy: https://www.riverbankcomputing.com/pipermail/pyqt/2020-September/043203.html - but it seems like he had given up and switched to iOS..
Any idea what I can do to investigate this behavior? I didn't modify anything regarding pyqtdeploy, Qt5, or the demo, all I'm doing is
pip3 install pyqtdeploy sip PyQt-builder
wget https://files.pythonhosted.org/packages/ab/8c/1416eaed51c87a5ac934ee982e5c6e0a9dcab8d9b0b0461d4b8b259db5f6/pyqtdeploy-3.1.0.tar.gz
tar xf pyqtdeploy-3.1.0.tar.gz
cd pyqtdeploy-3.1.0/demo
python3 build-demo.py --verbose
You obviously left some steps out here because in clean installs of Ubutu 18.04 LTS and 20.04 LTS I can't get far enough into what you did for it to actually attempt to build Qt.
Here is what I can tell you. In a clean Ubuntu 18.04 LTS VM I run this and can build either CopperSpice (a Qt 4.8 fork) or Qt code.
#
sudo apt-get install libfreetype6-dev libfontconfig1-dev libglib2.0-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libice-dev \
libaudio-dev libgl1-mesa-dev libc6-dev libsm-dev libxcursor-dev \
libxext-dev libxfixes-dev libxi-dev libxinerama-dev \
libxrandr-dev libxrender-dev libxkbcommon-dev \
libxkbcommon-x11-dev libx11-dev
sudo apt-get install libxcb1-dev libx11-xcb-dev libxcb-glx0-dev \
libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev \
libxcb-render0-dev libxcb-render-util0-dev \
libxcb-randr0-dev libxcb-shape0-dev libxcb-shm0-dev \
libxcb-sync-dev libxcb-xfixes0-dev \
libxcb-xinerama0-dev libxcb-xkb-dev
sudo apt-get install g++ gperf ninja-build cmake
sudo apt-get install libpulse-dev libasound2-dev libssl-dev libcups2-dev \
libxml++2.6-dev postgresql-server-dev-10
sudo apt-get install git
# extra for diamond
sudo apt-get install hunspell libhunspell-dev astyle
In a clean Ubuntu 20.04 LTS VM I run this script and can do the same.
#
sudo apt-get install libfreetype6-dev libfontconfig1-dev libglib2.0-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libice-dev \
libaudio-dev libgl1-mesa-dev libc6-dev libsm-dev libxcursor-dev \
libxext-dev libxfixes-dev libxi-dev libxinerama-dev \
libxrandr-dev libxrender-dev libxkbcommon-dev \
libxkbcommon-x11-dev libx11-dev
sudo apt-get install libxcb1-dev libx11-xcb-dev libxcb-glx0-dev \
libxcb-icccm4-dev libxcb-image0-dev libxcb-keysyms1-dev \
libxcb-render0-dev libxcb-render-util0-dev \
libxcb-randr0-dev libxcb-shape0-dev libxcb-shm0-dev \
libxcb-sync-dev libxcb-xfixes0-dev \
libxcb-xinerama0-dev libxcb-xkb-dev
sudo apt-get install g++ gperf ninja-build cmake
sudo apt-get install libpulse-dev libasound2-dev libssl-dev libcups2-dev \
libxml++2.6-dev postgresql-server-dev-12
sudo apt-get install git
# extra for diamond
sudo apt-get install hunspell libhunspell-dev astyle
So, what I suggest is that you pick one of your VMs, open a terminal,
sudo apt-get update
sudo apt-get upgrade
then run the appropriate script. I suspect you are falling over because of the XCB stuff. It shouldn't take you long to run one of those scripts in the appropriate VM to try this.
I am trying to install Python3.8 on Ubuntu 14.04, I get this error:
E: Unable to locate package python3.8 E: Couldn't find any package by
regex 'python3.8'
Is it even possible to have python3.8 on Ubuntu that is that old? If it is possible, please tell me how.
EDIT
When installing from source ( I followed that instruction)
I get this error:
Fatal Python error: _PySys_InitCore: can't initialize sys module
Python runtime state: preinitialized
Current thread 0x00002ab78e1b3740 (most recent call first): generate-posix-vars failed make: *** [pybuilddir.txt] Error 1
An alternative solution could be to compile python statically on a newer system. Then such binaries can be transferred to the target system.
Compilation tested on vanilla Ubuntu 20.04 LTS
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
$ wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
$ tar xzf Python-3.8.6.tgz
$ cd Python-3.8.6
$ ./configure LDFLAGS="-static" --disable-shared
$ make LDFLAGS="-static" LINKFORSHARED=" "
....
$ cd ..
$ zip -r Python-3.8.6.zip Python-3.8.6
Transfer Python-3.8.6.zip to target sysytem
$ unzip Python-3.8.6.zip
$ cd Python-3.8.6
$ ./python
Of course you would have to do
make install
or clean this folder, that's your choice.
Normally, as long as you are not using any kind of dockerization/paravirtualization, simple:
sudo snap install python38
should work.
I'm getting caffe import error even after installing it successfully using the command sudo apt install caffe-cpu. I was able to find caffe file at /usr/lib/python3/dist-packages/caffe (Path was added to PYTHONPATH). All requirements mentioned in the requirements.txt file of caffe directory was also installed.
I'm using Ubuntu 18.04 LTS, Python3.
Could anyone help me with this error?
import caffe
Traceback (most recent call last):
File "6_reconstruct_alphabet_image.py", line 17, in <module>
import caffe
File "/usr/lib/python3/dist-packages/caffe/__init__.py", line 1, in <module>
from .pycaffe import Net, SGDSolver, NesterovSolver, AdaGradSolver, RMSPropSolver, AdaDeltaSolver, AdamSolver, NCCL, Timer
File "/usr/lib/python3/dist-packages/caffe/pycaffe.py", line 15, in <module>
import caffe.io
File "/usr/lib/python3/dist-packages/caffe/io.py", line 2, in <module>
import skimage.io
File "/usr/lib/python3/dist-packages/skimage/__init__.py", line 158, in <module>
from .util.dtype import *
File "/usr/lib/python3/dist-packages/skimage/util/__init__.py", line 7, in <module>
from .arraycrop import crop
File "/usr/lib/python3/dist-packages/skimage/util/arraycrop.py", line 8, in <module>
from numpy.lib.arraypad import _validate_lengths
ImportError: cannot import name '_validate_lengths'
Problem solved: The error came up because caffe build wasn't done successfully. I recommend not to go up with the sudo apt install caffe-cpu command (Which is mentioned in the official caffe installation guide for Ubuntu); because it will end up in the error as above. It's better to install from the source.
Let me give step by step guidance to install caffe successfully in Ubuntu 18.04 LTS:
1] sudo apt-get install -y --no-install-recommends libboost-all-dev
2] sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev libboost-all-dev libhdf5-serial-dev \ libgflags-dev libgoogle-glog-dev liblmdb-dev protobuf-compiler
3] git clone https://github.com/BVLC/caffe
cd caffe
cp Makefile.config.example Makefile.config
4] sudo pip install scikit-image protobuf
cd python
for req in $(cat requirements.txt); do sudo pip install $req; done
5] Modify the Makefile.config file:
Uncomment the line CPU_ONLY := 1, and the line OPENCV_VERSION := 3.
6] Find LIBRARIES line in Makefile and change it to as follows:
LIBRARIES += glog gflags protobuf boost_system boost_filesystem m hdf5_hl hdf5 \
opencv_core opencv_highgui opencv_imgproc opencv_imgcodecs
7] make all
Now you could get some error like this:
CXX src/caffe/net.cpp
src/caffe/net.cpp:8:18: fatal error: hdf5.h: No such file or directory
compilation terminated.
Makefile:575: recipe for target '.build_release/src/caffe/net.o' failed
make: *** [.build_release/src/caffe/net.o] Error 1
To solve this error follow step 8.
8] install libhdf5-dev
open Makefile.config, locate line containing LIBRARY_DIRS and append /usr/lib /x86_64-linux-gnu/hdf5/serial
locate INCLUDE_DIRS and append /usr/include/hdf5/serial/ (per this SO answer)
rerun make all
9] make test
10] make runtest
11] make pycaffe
Now you could get some error like this:
CXX/LD -o python/caffe/_caffe.so python/caffe/_caffe.cpp
python/caffe/_caffe.cpp:10:31: fatal error: numpy/arrayobject.h: No such file or directory
compilation terminated.
Makefile:501: recipe for target 'python/caffe/_caffe.so' failed
make: *** [python/caffe/_caffe.so] Error 1
To solve this error follow step 12.
12] Find PYTHON_INCLUDE line in Makefile.config and do the changes as follows:
`PYTHON_INCLUDE := /usr/include/python2.7 \
/usr/local/lib/python2.7/dist-packages/numpy/core/include`
13] Add the module directory to our $PYTHONPATH by adding this line to the end of ~/.bashrc file:
`sudo vim ~/.bashrc`
`export PYTHONPATH=$HOME/Downloads/caffe/python:$PYTHONPATH`
`source ~/.bashrc'
14] Done.
This can be happened if there is any older version of the packages. Particularly, according to the Traceback, main reason can be the older version of scikit-image package. Just upgrade the package using the command.
for Python 2.7 : pip install --upgrade scikit-image
and
for Python 3.x : pip3 install --upgrade scikit-image
Installation of Caffe on ubuntu 18.04 in cpu mode .
conda update conda
conda create -n testcaffe python=3.5
source activate testcaffe
conda install -c menpo opencv3
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y build-essential cmake git pkg-config
sudo apt-get install -y libprotobuf-dev libleveldb-dev libsnappy-dev protobuf-compiler
sudo apt-get install -y libatlas-base-dev
sudo apt-get install -y --no-install-recommends libboost-all-dev
sudo apt-get install -y libgflags-dev libgoogle-glog-dev liblmdb-dev
mkdir build
cd build
make -j8 l8
make all
make install
conda install cython scikit-image ipython h5py nose pandas protobuf pyyaml jupyter
sed -i -e 's/python-dateutil>=1.4,<2/python-dateutil>=2.0/g' requirements.txt
for req in $(cat requirements.txt); do pip install $req; done
cd ../build
cd ../python
export PYTHONPATH=pwd${PYTHONPATH:+:${PYTHONPATH}}
python -c "import caffe;print(caffe.version)"
jupyter notebook
Complete steps just run these command as it is, Caffe will be installed in the system.
On Redhat 4.4.7-18 I am trying to run python3 code using sqlite, but I get the following import error:
Traceback (most recent call last):
File "database.py", line 7, in <module>
import sqlite3
File "/usr/local/lib/python3.6/sqlite3/__init__.py", line 23, in <module>
from sqlite3.dbapi2 import *
File "/usr/local/lib/python3.6/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
I tried to install it:
>sudo pip install sqlite3
Collecting sqlite3
Retrying (Retry(total=4, connect=None, read=None, redirect=None)) after connection broken by 'ProtocolError('Connection aborted.', error(101, 'Network is unreachable'))': /simple/sqlite3/
(while the network is reachable...) and with the following command:
> sudo yum install sqlite-devel
Loaded plugins: post-transaction-actions, product-id, refresh-packagekit,
: rhnplugin, search-disabled-repos, security, subscription-manager
This system is receiving updates from RHN Classic or RHN Satellite.
Setting up Install Process
Package sqlite-devel-3.6.20-1.el6_7.2.x86_64 already installed and latest version
Nothing to do
So it is installed and not installed? Any suggestion how I can solve the original problem?
Not a direct answer but I ended up here with my search engine... So for my fellow web-surfers:
I had a similar issue, but on ubuntu 16.04 with a manually compile python3.6 version :
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
I had to install libsqlite3-dev (sudo apt install libsqlite3-dev) and compile from the start python3.6 to make it work.
Yep.
sudo yum install sqlite-devel
Followed by rebuild of Python 3.8.3 from source did the trick. Thx!
I had this issue on linux mint 20 after sqlite3 successfully installed
from _sqlite3 import *
ModuleNotFoundError: No module named '_sqlite3'
also, could not import sqlite3 into python interpreter
Fix:
sudo apt install libsqlite3-dev
cd your python installer directory
./configure
sudo make install
It happens when you install Python using the source code and then compile.
Usually people tend to install python and sqlite into separate folders. This causes sqlite binary inaccessible to python executables.
To solve this problem, use a common folder to install BOTH, the Python as well as sqlite. So that python binary and sqlite binary, reside in the same bin folder.
Below example script will solve:
INSTALL_BASE_PATH="/home/<user>/<tools>"
cd ~
mkdir build
cd build
[ -f Python-3.9.10.tgz ] || wget --no-check-certificate https://www.python.org/ftp/python/3.9.10/Python-3.9.10.tgz
tar -zxvf Python-3.9.10.tgz
[ -f sqlite-autoconf-3380000.tar.gz ] || wget --no-check-certificate https://www.sqlite.org/2022/sqlite-autoconf-3380000.tar.gz
tar -zxvf sqlite-autoconf-3380000.tar.gz
cd sqlite-autoconf-3380000
./configure --prefix=${INSTALL_BASE_PATH}
make
make install
cd ../Python-3.9.10
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib configure
LDFLAGS="-L ${INSTALL_BASE_PATH}/lib"
CPPFLAGS="-I ${INSTALL_BASE_PATH}/include"
LD_RUN_PATH=${INSTALL_BASE_PATH}/lib make
./configure --prefix=${INSTALL_BASE_PATH}
make
make install
cd ~
LINE_TO_ADD="export PATH=${INSTALL_BASE_PATH}/bin:\$PATH"
if grep -q -v "${LINE_TO_ADD}" $HOME/.bashrc; then echo "${LINE_TO_ADD}" >> $HOME/.bashrc; fi
LINE_TO_ADD="export LD_LIBRARY_PATH=${INSTALL_BASE_PATH}/lib"
if grep -q -v "${LINE_TO_ADD}" $HOME/.bashrc; then echo "${LINE_TO_ADD}" >> $HOME/.bashrc; fi
source $HOME/.bashrc