i am a beginner i need to create a python virtual_environment for installing Django. I am using the following steps for installing python and virtualenv
cd /usr/src/
wget http://www.python.org/ftp/python/3.5.1./Python-3.5.1.tgz
tar zxf Python-3.5.1.tgz
cd python-3.5.1
mkdir /usr/local/python-3.5
./configure --prefix=/usr/local/python'.$python.' --with-threads --enable-shared --with-zlib=/usr/include && make && make altinstall
echo "/usr/local/python3.5/lib" > python3.5.conf
mv python3.5.conf /etc/ld.so.conf.d/python3.5.conf
/sbin/ldconfig
ln -sfn /usr/local/python3.5/bin/python3.5 /usr/bin/python3.5
wget https://pypi.python.org/packages/source/s/setuptools/setuptools-11.3.1.tar.gz
tar xzf setuptools-11.3.1.tar.gz
cd setuptools-11.3.1
/usr/local/python3.5/bin/python3.5 setup.py install
/usr/local/python3.5/bin/easy_install-3.5 pip
ln -sfn /usr/local/python3.5/bin/pip3.5 /usr/bin/pip3.5
/usr/local/python3.5/bin/pip3.5 install virtualenv
then i am created a virtualenv based on this,
and enter into python shell and use
import sqlite
i got following error
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'sqlite'
And i tried to run a django project installed in the virtalenv i got following errors.
raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc)
django.core.exceptions.ImproperlyConfigured: Error loading either pysqlite2 or sqlite3 modules (tried in that order): No module named '_sqlite3'
I am using CentOS release 6.8 (Final).
The python-bundled sqlite package is called sqlite3:
https://docs.python.org/3.6/library/sqlite3.html
So, just do
import sqlite3
and you should be good.
EDIT
I only now realized that you're building python yourself. So that's probably why the sqlite3 module is missing. Check the output of the configure call whether sqlite3 is mentioned.
I assume you'd have to get the development packages.
Any reason you are not using the EPEL Repository to install python?
Related
I am looking to install Python 3.10.9 and some packages behind a firewall on RHEL 7 machine.
I do not have administrative rights, nor access to elevated privileges. Some core requirements are missing to build items from source. I've been unable to build with OpenSSL, and thus can't pip install packages.
I prefer to stick to packaged solutions as much as possible, so I've pursued a path that allows installing dependencies with yum.
Relevant related questions
Preparing _tkinter and sqlite3 for Python installation (no admin rights)
Relevant lessons: How to install packages in Linux (CentOS) without root user with automatic dependency handling?
# Install prerequisites
mkdir ~/rpm
mkdir ~/rhel
yumdownloader --destdir ~/rpm --resolve zlib-devel bzip2 bzip2-devel readline-devel sqlite sqlite-devel openssl-devel tk-devel libffi-devel xz-devel libffi
cd ~/rhel && for i in ~/rpm/*.rpm; do rpm2cpio $i | cpio -idv; done
# Modify ~/.bashrc with necessary flags and includes. See .bashrc below
source ~/.bashrc
#Download pyenv and install
curl https://pyenv.run | bash
pyenv install 3.10.9
The part I seem to be getting stuck on, is correctly referencing the various libraries that are installed.
Rather than build dependencies from source, utilized yum to install:
Current ~/.bashrc
# For building custom YUM locally
export PATH="$HOME/rhel/usr/sbin:$HOME/rhel/usr/bin:$HOME/rhel/bin:$PATH"
export MANPATH="$HOME/rhel/usr/share/man:$MANPATH"
L='/lib:/lib64:/usr/lib:/usr/lib64'
export LD_LIBRARY_PATH="$HOME/rhel/usr/lib:$HOME/rhel/usr/lib64:$L"
# PyEnv install https://www.mpietruszka.com/install-pyenv-ce-rhel8.html
export PYENV_ROOT="$HOME/.pyenv"
command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
#export PKG_CONFIG_PATH=$HOME/rhel/usr/lib/pkgconfig:$PKG_CONFIG_PATH
#LDFLAGS
export LDFLAGS="-L$HOME/rhel/usr/lib -L$HOME/rhel/usr/lib64 -L/usr/lib -L/usr/lib64 -L/lib -L/lib64"
#CPPFLAGS
export CPPFLAGS="-I$HOME/rhel/usr/lib -I$HOME/rhel/usr/lib64 -I/usr/lib -I/usr/lib64 -I/lib -I/lib64"
#LD_Library
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$HOME/rhel/usr/include"
The errors I'm currently getting
pyenv install 3.10.9
Downloading Python-3.10.9.tar.xz...
-> https://www.python.org/ftp/python/3.10.9/Python-3.10.9.tar.xz
Installing Python-3.10.9...
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "~/.pyenv/versions/3.10.9/lib/python3.10/ctypes/__init__.py", line 8, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
WARNING: The Python ctypes extension was not compiled. Missing the libffi lib?
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'readline'
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "~/.pyenv/versions/3.10.9/lib/python3.10/ssl.py", line 99, in <module>
import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
Please consult to the Wiki page to fix the problem.
https://github.com/pyenv/pyenv/wiki/Common-build-problems
BUILD FAILED (RedHatEnterpriseServer 7.7 using python-build 20180424)
Inspect or clean up the working tree at /tmp/python-build.20230208180402.153250
Results logged to /tmp/python-build.20230208180402.153250.log
Last 10 log lines:
$ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmp540mosi3
Processing /tmp/tmp540mosi3/setuptools-65.5.0-py3-none-any.whl
Processing /tmp/tmp540mosi3/pip-22.3.1-py3-none-any.whl
Installing collected packages: setuptools, pip
WARNING: The scripts pip3 and pip3.10 are installed in '~/.pyenv/versions/3.10.9/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed pip-22.3.1 setuptools-65.5.0
make: warning: Clock skew detected. Your build may be incomplete.
I'd appreciate some criticism on correctly calling these libraries...
I can't import standard library modules (like ssl and tkinter) when I'm not running Python from "/Python3.8.10/Modules" directory:
/Python3.8.10/Modules/# python
>>> import ssl
Traceback(most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/ssl.py", line 98, in <module>
import _ssl # if we can't import it, let the error propagate
ModuleNotFoundError: No module named '_ssl'
Same error happens if I try to import "_ssl" directly.
When I'm running Python in /Python3.8.10/Modules" directory everything works fine.
What could be causing this error?
I am using Debian and I used this tutorial https://linuxhint.com/install-python-debian-10/ to install it.
Judging from your comment you didn't install Python, but just downloaded and unzipped the Source Code.
I am on Debian. I unzipped (untar-ed) Python-3.8.10.tgz (Which comes from the Python website).
If you download the tar ball directly you still have to build Python by cd-ing into the Location you extracted it to and then running:
$ ./configure --enable-optimizations
$ make -j 4
$ sudo make altinstall # altinstall will install Python3.8 at /usr/bin/Python3.8 instead of /usr/bin/Python which could overwrite previously installed versions.
$ sudo ln -s /usr/bin/python /usr/bin/python3.8 # ONLY if you want Python3.8 to be available as just python
Edit: Those are just the commands that i remembered out of my head which worked for me on various systems. They also have some requirements (build-essentials and make being two of them) so this might not work for you.
See here or probably on any site when searching for build Python from source in your favorite search engine.
I am having difficulty installing the ibm_db package for Python 3.4 on a 32 bit windows virtual server. I have tried easy_install, pip, and installing the pacakge manually. When I used pip install I am able to reference the package with import ibm_db, but I am not able to use it without getting the following error:
Traceback (most recent call last):
File "C:/Python34/Lib/site-packages/ibm_db-2.0.6-py3.4.egg/ibm_db.py", line 10, in <module>
__bootstrap__()
File "C:/Python34/Lib/site-packages/ibm_db-2.0.6-py3.4.egg/ibm_db.py", line 9, in __bootstrap__
imp.load_dynamic(__name__,__file__)
ImportError: DLL load failed: The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
When I use easy_install I am unable to reference the library using import ibm_db. I was wondering if there was a simple solution to this.
How to make ibm_db work on MAC
Make sure that you has IBM DB2 EXPRESS 2 installed on your machine:
https://www.ibm.com/analytics/us/en/db2/trials/?S_CMP=ECDDWW01&S_TACT=ACDB201
To install the DB2 EXPRESS 2 extact the files into your computer and:
cd ~/Downloads/expc ; sudo ./db2_install
Make sure that you has your $HOSTNAME variable properly configured:
echo "127.0.0.1 $HOSTNAME" >>/etc/hosts
Create another user using mac gui
(System Preferences -> Users & Groups). Use Standard (Non-Admin) privileges.
Create the instance with these commands:
cd /opt/IBM/db2/V10.1/instance ; sudo ./db2icrt -u <newuser> <newuser>
Export the following variables
$ sudo -s
$ export IBM_DB_LIB=/Users/<newuser>/sqllib/lib64
$ export IBM_DB_DIR=/Users/<newuser>/sqllib
$ export ARCHFLAGS="-arch x86_64"
Intall ibm_db
pip3 install ibm_db
Try easy_install ibm_db, it worked for me on both Linux and Windows.
Similar problem has been addressed here:
https://groups.google.com/forum/#!topic/ibm_db/-HaQ48BhcfQ
Please check if that helps!
Attempt to install psutils resulted a big headache...
$ python -V
Python 2.4.2
$ cat /etc/SuSE-release
SUSE Linux Enterprise Server 10 (x86_64)
VERSION = 10
PATCHLEVEL = 4
$ cd psutil-2.1.1/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 17, in ?
from distutils.core import setup, Extension
ImportError: No module named distutils.core
Next - I try to install setuptools to use easy_install:
$ which easy_install
which: no easy_install
$ cd ../setuptools-1.4/
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 12, in ?
from distutils.util import convert_path
ImportError: No module named distutils.util
Trying install distutils from ez_setup.py:
$ python ez_setup.py
Traceback (most recent call last):
File "ez_setup.py", line 278, in ?
main(sys.argv[1:])
File "ez_setup.py", line 210, in main
egg = download_setuptools(version, delay=0)
File "ez_setup.py", line 139, in download_setuptools
from distutils import log
ImportError: No module named distutils
So - how can I install it?
P.S. No, I haven't root on this machine and can't use package manager.
you need to run this (if Error happens on python3) ==> sudo apt-get install python3-distutils --reinstall
you need to run this (if Error happens on python2) ==> sudo apt-get install python2-distutils --reinstall
I have an answer here but I will copy it here
AskUbuntu answer:
Debian has decided that distutils is not a core python package, so it is not included in the last versions of debian and debian-based OSes. You should be able to do sudo apt install python3-distutils and it should work.
However, it did not work for me. I use Parrot OS, which is, as Ubuntu, Debian based. I upgraded my system and pip stopped working for python3.7, and I also got the error ModuleNotFoundError: No module named 'distutils.util'
I tried a lot of stuff to fix it and to reinstall distutils, and I found out by pure luck, that pip3, for python3.8 did work. I then tried python3.7 -m pip3 -V, got /usr/bin/python3.7: No module named pip3 so I decided to have a look in the /usr/lib files.
I looked at /usr/lib/python3/dist-packages and everything looked fine. Then I looked at /usr/lib/python3.7 and saw the folder distutil.
I opened it, and saw the __pycache__, the __init__.py file and a version.py file. I had no idea how many files should be in there, or what the code should be, but I knew that those two files were either wrong or missing another file.
Then I had a look at what was inside /usr/lib/python3.8/distutil and it was totally different. I found the following files:
command Folder
__pycache__ Folder
archive_util.py Python script
bcppcompiler.py Python script
cmd.py Python script
config.py Python script
core.py Python script
cygwinccompiler.py Python script
debug.py Python script
dep_util.py Python script
errors.py Python script
extension.py Python script
fancy_getopt.py Python script
filelist.py Python script
file_util.py Python script
__init__.py Python script
log.py Python script
msvc9compiler.py Python script
_msvccompiler.py Python script
msvccompiler.py Python script
README Plain text file
spawn.py Python script
sysconfig.py Python script
text_file.py Python script
unixccompiler.py Python script
util.py Python script
version.py Python script
versionpredicate.py Python script
This was a lot more promising, and since pip3 did work, I assumed that this distutils worked too, and I tried to copy it to the python3.7 folder by running this command:
sudo cp -r /usr/lib/python3.8/distutil /usr/lib/python3.7/distutil
Then I tried again python3.7 -m pip -V and got
pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.7)
Then I tried installing some modules and everything works fine.
I hope this is helpful.
#ciro
I need to do even more to get virtualenv running again (upgraded from 18.04 to 20.04):
sudo cp /usr/lib/python3.8/_sysconfigdata__* /usr/lib/python3.6/
cd /usr/lib/python3.6
sudo ln -s _sysconfigdata_m_linux_x86_64-linux-gnu.py _sysconfigdata_m_x86_64-linux-gnu.py
There might be other questions similar to this but, in my particular case, I don't have super user (sudo) access to the machine and I have locally installed Python 2.7.
>>> import sqlite3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/spicmacay/.local/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
from dbapi2 import *
File "/home/spicmacay/.local/lib/python2.7/sqlite3/dbapi2.py", line 27, in <module>
from _sqlite3 import *
ImportError: No module named _sqlite3
>>>
UPDATE: When I run ./configure&& make, I get:
make
running build
running build_ext
building dbm using gdbm
INFO: Can't locate Tcl/Tk libs and/or headers
Python build finished, but the necessary bits to build these modules were not found:
_sqlite3 _tkinter bsddb185
dl imageop sunaudiodev
To find the necessary bits, look in setup.py in detect_modules() for the module's name.
running build_scripts
Came to this issue also.. fixed by compiling Python and passing sqlite3 headers/libs during ./configure
Python 2.7.3 _sqlite3 module is not being built after passing headers/libraries
Posted just in case anyone else has this issue in the future and does not have sudo access to a node.
This happened me recently. You need to apt-get install libsqlite3-dev (on debian - sqlite-devel possibly elsewhere) and recompile python.
If you first ./configure sqlite3 with a --prefix option, then make and make install it and then use the same --prefix when compiling Python, the Python installation will be able to magically find and use the sqlite3 you just installed.
cd sqlite-autoconf-3080100
./configure --prefix=/home/xdanek7/appscale/local
make
make install
cd ../Python-2.7.6
./configure --prefix=/home/xdanek7/appscale/local
make
make install
Try adding sudo before the command apt-get install libsqlite3-dev to get rid of "NO root access"
i.e on terminal, write:
sudo apt-get install libsqlite3-dev