s3cmd ImportError: No module named S3.Exceptions - python

Received an error after installing and trying to run s3cmd 1.0.0
s3cmd -h
Problem: ImportError: No module named S3.Exceptions
S3cmd: unknown version. Module import problem?
Traceback (most recent call last):
File "/usr/bin/s3cmd", line 1995, in <module>
from S3.Exceptions import *
ImportError: No module named S3.Exceptions
Your sys.path contains these entries:
This error came about after upgrading to the latest Amazon Linux distro 2015.03.0

Looks like the error happened because python2.7 is now the default python version in the Amazon Linux 2015.03.0+ If you change python back to 2.6 and run s3cmd it should work without a problem
update-alternatives --set python /usr/bin/python2.6
s3cmd -h
After the s3cmd command is ran you can put python back to 2.7 for yum and other utilities:
update-alternatives --set python /usr/bin/python2.7
yum install <package>

vi /usr/bin/s3cmd
add 2.6 to the first line, so it looks like:
#!/usr/bin/python2.6
Save thefile and s3cmd will work. as long as you have /usr/bin/python2.6 on your system

I faced a similar error with s3cmd, but module name was different:
ImportError: No module named S3.ExitCodes
In my case I could solve the problem this way:
yum install python-pip and then pip install s3cmd.
After that s3cmd worked fine.

Neither of the previous answers worked for me, but copying a few lines from the sourcegraph aws-cli dockerfile did:
FROM python:2
RUN apt-get update -q
RUN apt-get install -qy python-pip groff-base
RUN pip install awscli

s3cmd was working with one version of my python in sys.path, it was keeping up some other version.
sudo vi /usr/bin/s3cmd
You will see this in starting lines.
import sys
I had two python version python3.5 and python3.6
Lets run python3.5 and then python3.6
import sys
print('\n'.join(sys.path))
Match your sys path with s3cmd error sys path. This will give you assurance that you need to change the python version in sys path for that.
Now: How to Change sys.path python version?
echo $PYTHONPATH
sudo vi ~/.bashrc
export PYTHONPATH=/usr/bin/python3.6
PYTHONPATH Help Link

Related

How to install sqlite3 for python3.7 in seperate directory on linux without sudo commands?

I have the problem that when I run my code on a linux server I get:
ModuleNotFoundError: No module named '_sqlite3'
So after researching, I found out sqlite3 was supposed to have been installed when I installed python, however it didn't.
I think the problem comes from the way I installed python. Since I do not have sudo permissions, I installed python3.7 in a local directory using: This guide.
All solutions to this sqlite3 problem that I can find requires sudo commands.
Is there another way that I can install python3.7 together with sqlite3 in my local Linux directory without using any sudo commands?
I hope I have stated my question clearly and I would appreciate all the help I can get. Thank you!
While installing a python package in a Linux system without "sudo" privileges you can use
For Python 3
pip3 install --user pysqlite3
You can install any third party packages with the same method
pip3 install --user PACKAGE_NAME
The --user flag to pip install tells Pip to install packages in some specific directories within your home directory. For more information click here.
Hope it helps !
The solution is to first build sqlite3 into a user directory and then build python using that directory's libraries and include headers. In particular, #Ski has answered a similar question regarding python 2, which can be adopted to python 3:
$ mkdir -p ~/applications/src
$ cd ~/applications/src
$ # Download and build sqlite 3 (you might want to get a newer version)
$ wget http://www.sqlite.org/sqlite-autoconf-3070900.tar.gz
$ tar xvvf sqlite-autoconf-3070900.tar.gz
$ cd sqlite-autoconf-3070900
$ ./configure --prefix=~/applications
$ make
$ make install
$ # Now download and build python 2, same works for python 3
$ cd ~/applications/src
$ wget http://www.python.org/ftp/python/2.5.2/Python-2.5.2.tgz
$ tar xvvf Python-2.5.2.tgz
$ cd Python-2.5.2
$ ./configure --prefix=~/applications
$ make
$ make install
$ ~/applications/bin/python
Alternatively, if you already have to specify a different --prefix for some reason (this has happened to me with pyenv), use LDFLAGS and CPPFLAGS when configuring python build:
$ ./configure LDFLAGS=-L/home/user/applications/lib/ CPPFLAGS=-I/home/user/applications/include/

django can't find new sqlite version? (SQLite 3.8.3 or later is required (found 3.7.17))

I've cloned a django project to a Centos 7 vps and I'm trying to run it now, but I get this error when trying to migrate:
$ python manage.py migrate
django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required (found 3.7.17).
When I checked the version for sqlite, it was 3.7.17, so I downloaded the newest version from sqlite website and replaced it with the old one, and now when I version it, it gives:
$ sqlite3 --version
3.27.2 2019-02-25 16:06:06 bd49a8271d650fa89e446b42e513b595a717b9212c91dd384aab871fc1d0f6d7
Still when I try to migrate the project, I get the exact same message as before which means the newer version is not found. I'm new to linux and would appreciate any help.
I got the same error in CentOS 7.6 and Python 3.7.3 versions. I think you are using Django 2.2.* some version. In latest of Django 2.2, they changed the SQLIte version, that cause of your problem.
This is the release notes of Django 2.2 about SQLite.
The minimum supported version of SQLite is increased from 3.7.15 to 3.8.3.
So I found 3 steps to solve this problem,
Downgrade Django Version
So you can install latest version of Django 2.1 by using this command, which mean you're going to downgrade your Django version.
pip install Django==2.1.*
Upgrading SQLite on CentOS to 3.8.3 or Later
or you can followup below steps as well to keep the latest version Django. I directly get the steps from Upgrading SQLite on CentOS to 3.8.3 or Later article.
You can download the latest sqlite version from here.
wget https://www.sqlite.org/2019/sqlite-autoconf-3280000.tar.gz
tar zxvf sqlite-autoconf-3280000.tar.gz
./configure
make
sudo make install
We've installed to the latest version, but the problem is same. Here,
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
In the article, they've mentioned about LD_RUN_PATH and LD_LIBRARY_PATH paths.
Then make sure to compile python again using the LD_RUN_PATH environment variable.
It is better to use this variable over LD_LIBRARY_PATH.
Using LD_LIBRARY_PATH - whenever python is run it will look for linked libraries with that path.
What we want is for the libraries to be cooked into python at link time - compile time.
So based on the article, we can do the similar thing,
cd /opt/Python-x.y.z
LD_RUN_PATH=/usr/local/lib ./configure
LD_RUN_PATH=/usr/local/lib make
LD_RUN_PATH=/usr/local/lib make altinstall
Then try again,
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.31.1'
Here we go, one thing they've mentioned,
If you do not use LD_RUN_PATH, then you have to make sure that the LD_RUN_PATH environment variable is set to /usr/local/lib for every user that is going to run python - which can be really annoying to do.
testing a Django 2.2 website with SQLite3 on CentOS 7
This is same as the previous one and based on LD_LIBRARY_PATH approach. Here is the steps from the article,
$ wget https://www.sqlite.org/2018/sqlite-autoconf-3240000.tar.gz
$ tar zxvf sqlite-autoconf-3240000.tar.gz
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.7.17
$
$ export LD_LIBRARY_PATH=/usr/local/lib
$ python3.6 -c "import sqlite3; print(sqlite3.sqlite_version)"
3.24.0
If the last two steps didn't work, please comment below with the error you got and I'll find another solution for you.
I solved a similar situation with the following patches of code. Follow these steps that I used on my own centos7 & everything should be alright.
Just remember to let your centos7 know that you are calling python3 not just python otherwise it will call the default python2 followed by a series of errors in your virtualenv.
Installing python3 (from source):
cd ~
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar xJf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure
make && make install
export PATH=$HOME/opt/python-3.7.3/bin:$PATH
Then run: source .bash_profile
Confirming by
python3 --version
Python 3.7.3
Installing your sqlite3 (from source):
$ cd ~
$ wget https://www.sqlite.org/2019/sqlite-autoconf-3290000.tar.gz
$ tar zxvf sqlite-autoconf-3290000.tar.gz
cd sqlite-autoconf-3290000
$./configure --prefix=$HOME/opt/sqlite
$ make && make install
Now this is what you should also remember to do for centos7 know where to look for your python3 and not defaulting to python2. On your .bash_profile copy & past this piece of code or edit the paths accordingly:
export PATH=$HOME/opt/sqlite/bin:$PATH
export LD_LIBRARY_PATH=$HOME/opt/sqlite/lib
export LD_RUN_PATH=$HOME/opt/sqlite/lib
Make it permanent by running: source .bash_profile
and you are done with sqlite3 version >= 3.8. Confirm it by:
sqlite3 --version
3.29.0 2019-07-10 17:32:03
And then you can continue to use python3 to install python3 modules like django-2.2.
python3.7 -m pip3 install virtualenv
(myvenv37)[me#test my_project]$ python3.7 -m pip3 install django
Successfully installed django-2.2.3 pytz-2019.1 sqlparse-0.3.0
Remember, it is
PYTHON3.7 -m pip3 install MODULE
(myvenv37)[me#test my_project]$ python3.7 manage.py runserver
and the server should be running.
So, to conclude, in the case above it was migrate, & should look like this:
(venv)[me#test my_project]$ python3.7 manage.py migrate
As this was about Centos7, you can use the Fedora package to upgrade the Centos sqlite package:
wget https://kojipkgs.fedoraproject.org//packages/sqlite/3.8.11/1.fc21/x86_64/sqlite-3.8.11-1.fc21.x86_64.rpm
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm
(from: https://www.reddit.com/r/linuxadmin/comments/c9hy5w/trying_to_upgrade_sqlite_3717_to_version_38_on/ezrtbkm/?utm_source=reddit&utm_medium=web2x&context=3)
This seems to work, although I'm never sure if doing this is really an ideal solution to a problem or not. I guess if you're not actually using SQLite, then this at least passes the version check and so gets you working.
django 2.2 need sqlite version >= 3.8.3
so the solution is update your sqlite:
download from sqlite3, select source_code version
tar -zxvf sqlite-xxx.tar.gz && cd xx
./configure && make && make install
mv /usr/bin/sqlite3 /usr/bin/sqlite3.bak
mv xxx/sqlite3 /usr/bin/sqlite3
export LD_LIBRARY_PATH="/usr/local/lib" and write it into ~/.bashrc
test1 :
sqlite3 --version
should be your version
test2:
$python
>>> import sqlite3
>>> sqlite3.sqlite_version
should be your version
To check which version of SQLite Python is using:
$ python
Python 3.7.3 (default, Apr 12 2019, 16:23:13)
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.27.2'
For me the new version of sqlite3 is in /usr/local/bin so I had to recompile Python, telling it to look there:
sudo LD_RUN_PATH=/usr/local/lib ./configure --enable-optimizations
sudo LD_RUN_PATH=/usr/local/lib make altinstall
I had the same issue and I struggled with it for a while. For me the best solution was to comment out DATABASES section in settings.py file.
As I don't want to use SQLite database then issue does not exist anymore. Later on you can update DATABASE information with the db that is valid for you.
I was having trouble with the above solutions on an Amazon Linux 2 instance and found that what was installed from my various attempts to update were causing version conflicts.
Initially I had this:
$ python3 --version
Python 3.7.9
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.7.17'
>>> exit()
And sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm failed to install with this message:
I resolved it by the following steps:
sudo yum list | grep sqlite
These two packages were preventing updates due to conflict.
sudo yum autoremove sqlite-devel To uninstall the extraneous package.
sudo yum install sqlite-3.8.11-1.fc21.x86_64.rpm To update the version.
sudo yum list | grep sqlite
New list of updated sqlite packages:
$ python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.11'
>>> exit()
You will only get make it worse with errors like multilib and other incompatibilities if keeps forcing the installation of sqlite 3.8.3 or higher. Just as Theo commented, the best approach is to comment the line #66 on the sqlite3/base.py (file within django) that triggers the method named check_sqlite_version().
This should be just warning that you are using a minor patch instead of raise an Exception (ImproperlyConfigured).
PD: Just make sure to document it!
After few hours of searching I solved it using one command inside my virtual environment:
pip install pysqlite3-binary
You can check github here and article(a bit outdated) here.
I also found here that you should then place the following lines of code in your settings.py:
__import__('pysqlite3')
import sys
sys.modules['sqlite3'] = sys.modules.pop('pysqlite3')
but for me it worked without it.
another option is to use atomic repo
wget -O - http://updates.atomicorp.com/installers/atomic |sh
yum install atomic-sqlite
LD_LIBRARY_PATH='/opt/atomicorp/atomic/root/usr/lib64/' python3
>>> import sqlite3
>>> sqlite3.sqlite_version
'3.8.5'
I answered this question here: ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)
I solved this issue by upgrading my version of sqlite3 using this command:
cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install
I am using ElasticBeanstalk for my setup, so I added a .config file to the .ebextensions folder and put this in it:
option_settings:
aws:elasticbeanstalk:application:environment:
LD_LIBRARY_PATH: "/usr/local/lib"
commands:
01_upgrade_sqlite:
command: "cd ~ && wget https://www.sqlite.org/2020/sqlite-autoconf-3320100.tar.gz && tar xvfz sqlite-autoconf-3320100.tar.gz && cd sqlite-autoconf-3320100 && ./configure && make && make install"
Many thanks to Bejür for adding the LD_LIBRARY_PATH environment variable here in order to get it to work.
I make a fixed downgrade Django
pip3 install Django==2.1.*
i had recently same problem
My solution was to change source code site-packages\django\db\backends\sqlite3\base.py line around 68 So far no side effects.
def check_sqlite_version():
if Database.sqlite_version_info < (3, 7, 3):
raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version)

How to create a Python 3.5 virtual environment with Python 2.7?

My system is running CentOS 6. I do not have admin access, so sudo is not available. I have Python 2.7.3 available, along with pip and virtualenv. I was hoping that I could use these to set up a new virtual environment in which to install & run Python 3.5 or above.
I tried the method described here:
Using Python 3 in virtualenv
But got this error:
$ virtualenv -p python3 venv
The path python3 (from --python=python3) does not exist
My system also has a Python 3.4 module installed, so I tried that, however virtualenv does not seem to work there:
$ module load python/3.4.3
$ virtualenv -p python3 venv
-bash: virtualenv: command not found
This appears to make sense since virtualenv is only installed for Python 2.7:
$ module unload python
$ module load python/2.7
$ which virtualenv
/local/apps/python/2.7.3/bin/virtualenv
So, the next logical step would seem to be installing virtualenv for my Python 3... but this does not work either:
$ pip3 install virtualenv
Traceback (most recent call last):
File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
also
$ pip3 install --user virtualenv
Traceback (most recent call last):
File "/local/apps/python/3.4.3/bin/pip3", line 7, in <module>
from pip import main
ImportError: cannot import name 'main'
I started Google'ing this new error message, but did not see anything that seemed relevant for this situation. Any ideas? Even if I could get virtualenv installed on my Python 3.4 module, would I still be unable to upgrade it to Python 3.5+?
To round things out, I also tried to compile my own Python 3.6 from source, but that does not work either:
Python-3.6.0$ make install
if test "no-framework" = "no-framework" ; then \
/usr/bin/install -c python /usr/local/bin/python3.6m; \
else \
/usr/bin/install -c -s Mac/pythonw /usr/local/bin/python3.6m; \
fi
/usr/bin/install: cannot create regular file `/usr/local/bin/python3.6m': Permission denied
make: *** [altbininstall] Error 1
more background info:
$ which pip3
/local/apps/python/3.4.3/bin/pip3
$ which python
/local/apps/python/3.4.3/bin/python
You can download miniconda or Anaconda. It does not require superuser privileges because it installs in your home directory. After you install you can create new environments like this:
conda create -n py35 python=3.5
Then you can switch to the new environment:
source activate py35
Try this for Windows.
virtualenv -p C:\Python35\python.exe django_concurrent_env
cd django_concurrent_env
.\Source\activate
deactivate
Try out the following commands:
pip3 install virtualenv
pip3 install virtualenvwrapper
mkdir ~/.virtualenvs
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
source ~/.bash_profile
which python3
Now copy the result of path of python3 in the last command and put it in the following command:
mkvirtualenv --python=python3/path/in/last/command myenv
I'm assuming pip3 is already installed. If not, install it before running these commands.
Source: https://docs.coala.io/en/latest/Help/MAC_Hints.html#create-virtual-environments-with-pyvenv
(I do have sudo access on my machine. I've not tried the commands without it. Please post if any issues comes.)
Since you already have virtualenv installed, you might only need to update the files and then run the command mkvirtualenv with proper arguments.

-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied

I am new in centos.I am try to do an application on it.For my application I need to install python 2.7.But the default one on server was python 2.6. So tried to upgrade the version .And accidentally I deleted the folder /usr/bin/python.After that I Installed python 2.7 through make install.I created the folder again /usr/bin/python and run command sudo ln -s /usr/bin/python2.7 /usr/bin/python. After this when I tried to run YUM commands I am getting the error
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied
drwxrwxrwx 2 root root 4096 Mar 8 00:19 python
this is permission showing for the directory /usr/bin/python
CentOS requires that /usr/bin/python be pointed to Python 2.6, not any other version. Run the following commands:
sudo rm -rf /usr/bin/python
sudo ln -s /usr/bin/python2.6 /usr/bin/python
to at least fix that part of it. Next time you're building Python, use the defaults and install it to /usr/local/bin, not /usr/bin. That's what the /usr/local hierarchy is for - user-installed programs. /usr and /usr/bin should only be for system-installed programs (such as those installed by yum or its graphical equivalents), and you should keep out unless you know what you're doing. To use identically-named programs in /usr/local/bin instead of their counterparts in /usr/bin, open your ~/.bashrc or ~/.bash_profile (whichever your system uses) and add the following as the last line:
export PATH=/usr/local/bin:$PATH
Restart your shell session, and you should be all set.
yum doesn't work with python2.7.
You should do the following
vim /usr/bin/yum
change
#!/usr/bin/python
to
#!/usr/bin/python2.6
If your python2.6 was deleted, then reinstall them and point the directory in /usr/bin/yum to your python2.6 directory.
It is very simple; because the Python package was removed, the yum command won't work.
Please use below link to install packages:
Go to Link and download python package
wget http://mirror.centos.org/centos/7/sclo/x86_64/rh/python27/python27-1.1-26.1.el7.x86_64.rpm
rpm -ivh python27-1.1-26.1.el7.x86_64.rpm
Then yum will work.
this problem is that yum file start head write #!/usr/local/bin/python2.6, write binary file, is not dir, is python binary file
Resolution for CentOs 7:
dnf reinstall python-2.7.5-92.el7_9.x86_64
dnf reinstall yum
Remove python3 first using dnf if it is installed already.
-bash: /usr/bin/yum: /usr/bin/python: bad interpreter: Permission denied then
first remove python follow command line
-- sudo rpm -e python
second check which package install this command line
-- sudo rpm -q python
then install package
-- sudo yum install python*
i think this problem solve

RPi SPI spidev python

I am trying to get data from sensors with mcp 3002.
I always get this error:
importError: no module named spidev.
I have tried the following:
mkdir py-spidev
cd py-spidev
wget https://raw.github.com/doceme/py-spidev/master/setup.py
wget https://raw.github.com/doceme/py-spidev/master/spidev_module.c
sudo python setup.py install
but got the error
spydev_module.c:no such file or directory
What can I do?
I think you have to define the path correctly.
cd \examplepath\examplefile\
Then install the module by Python setup.py install
Try installing with python3 since it appears you have multiple python versions on your computer:
sudo python3 setup.py install

Categories

Resources