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
Related
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/
I am having this error when I try to run a Python file. I tried opening a new terminal and importing cv2 worked there in Python but doesn't work in my OpenCV virtual environment. I don't even understand how virtualenvs work but I have to find a solution for this.
> (cv) pi#raspberrypi:~/Camerafeed $ python run.py Traceback (most
> recent call last): File "run.py", line 2, in <module>
> from camerafeed import CameraFeed File "/home/pi/Camerafeed/camerafeed/__init__.py", line 5, in <module>
> import cv2 ImportError: No module named 'cv2'
I referred below link to solve the error of "no module Named cv2":
https://qengineering.eu/install-opencv-4.4-on-raspberry-pi-4.html
I copied manually the cv2 as suggested by the above link as below:
For Python 2:
$ cd ~/opencv/build/lib/ $ sudo cp cv2.so /usr/local/lib/python2.7/dist-packages/cv2/python-2.7
For Python 3:
$ cd ~/opencv/build/lib/python3 $ sudo cp cv2.cpython-37m-arm-linux-gnueabihf.so \ /usr/local/lib/python3.7/dist-packages/cv2/python-3.7
Ensure that you create cv2 dir first if you got error.
python -c "import cv2" is a quick indicator to import module, you can use it in either of your environments as a check.
My guess is that you should install the module while you are in (cv) environment by running pip install opencv-python at command prompt.
I believe numpy is already installed. If not then sudo apt-get install python-numpy to install opencv2
Now you can run this command to install Opencv:
sudo apt update && sudo apt-get install python-opencv python-scipy ipython
For more help you can also refer to this link
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
I am trying to setup mysqlfailover utility on ec2 instance running Ubuntu 12.04. I performed the following steps:
Downloaded mysql-connector-python:
wget http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python_1.0.12-1debian6.0_all.deb -o mysql-connector-python_1.0.12-1debian6.0_all.deb
(Installed using dpkg -i command.)
Download mysql-utilities:
wget http://cdn.mysql.com/Downloads/MySQLGUITools/mysql-utilities_1.3.5-1debian6.0_all.deb -o mysql-utilities_1.3.5-1debian6.0_all.deb
(Installed using dpkg -i command.)
There were some dependencies issues. I ran the following commands:
sudo apt-get install python-pip
easy_install -U distribute
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
pip install mysql-python
Now, when I run the command mysqlfailover, it gives the following error:
Traceback (most recent call last):
File "/usr/bin/mysqlfailover", line 24, in <module>
from mysql.utilities.common.tools import check_python_version
ImportError: No module named mysql.utilities.common.tools
I have been banging my head around quite some time now, but no success. Any help in the matter is highly appreciated. Thanks.
Try env PYTHONPATH=/usr/share/pyshared/ mysqlfailover
Thers is no utilities in mysql modul, you can check this do:
ls /usr/lib/python2.7/dist-packages/mysql
So you should change mysql package:
cp -r /usr/share/pysharedmysql /usr/lib/python2.7/dist-packages/mysql
Am on Debian 5, I've been trying to install cx_oracle module for python without any success. First, I installed oracle-xe-client and its dependency (followed tutorial in the following link here).
Then, I used the scripts in /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/bin to populate environment variables such as PATH, ORACLE_HOME and NLS_LANG.
Once, this was completed, I tried to run:
sudo easy_install cx_oracle
But I keep getting the following error:
Searching for cx-oracle
Reading http://pypi.python.org/simple/cx_oracle/
Reading http://cx-oracle.sourceforge.net
Reading http://starship.python.net/crew/atuining
Best match: cx-Oracle 5.0.4
Downloading http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-5.0.4.tar.gz?download
Processing cx_Oracle-5.0.4.tar.gz
Running cx_Oracle-5.0.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-xsylvG/cx_Oracle-5.0.4/egg-dist-tmp-8KoqIx
error: cannot locate an Oracle software installation
Any idea what I missed here?
The alternate way, that doesn't require RPMs. You need to be root.
Dependencies
Install the following packages:
apt-get install python-dev build-essential libaio1
Download Instant Client for Linux x86-64
Download the following files from Oracle's download site:
Extract the zip files
Unzip the downloaded zip files to some directory, I'm using:
/opt/ora/
Add environment variables
Create a file in /etc/profile.d/oracle.sh that includes
export ORACLE_HOME=/opt/ora/instantclient_11_2
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME
Create a file in /etc/ld.so.conf.d/oracle.conf that includes
/opt/ora/instantclient_11_2
Execute the following command
sudo ldconfig
Note: you may need to reboot to apply settings
Create a symlink
cd $ORACLE_HOME
ln -s libclntsh.so.11.1 libclntsh.so
Install cx_Oracle python package
You may install using pip
pip install cx_Oracle
Or install manually
Download the cx_Oracle source zip that corresponds with your Python and Oracle version. Then expand the archive, and run from the extracted directory:
python setup.py build
python setup.py install
I recommend that you grab the rpm files and install them with alien. That way, you can later on run apt-get purge no-longer-needed.
In my case, the only env variable I needed is LD_LIBRARY_PATH, so I did:
echo export LD_LIBRARY_PATH=/usr/lib/oracle/11.2/client/lib >> ~/.bashrc
source ~/.bashrc
I suppose in your case that path variable will be /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib.
The following worked for me, both on mac and Linux. This one command should download needed additional files, without need need to set environment variables.
python -m pip install cx_Oracle --pre
Note, the --pre option is for development and pre-release of the Oracle driver. As of this posting, it was grabbing cx_Oracle-6.0rc1.tar.gz, which was needed. (I'm using python 3.6)
Thx Burhan Khalid, I overlooked your "You need to be root" quote, but found the way when you are not the root here.
At point 7 you need to use:
sudo env ORACLE_HOME=$ORACLE_HOME python setup.py install
Or
sudo env ORACLE_HOME=/path/to/instantclient python setup.py install
Thanks Burhan Khalid. Your advice to make a a soft link make my installation finally work.
To recap:
You need both the basic version and the SDK version of instant client
You need to set both LD_LIBRARY_PATH and ORACLE_HOME
You need to create a soft link (ln -s libclntsh.so.12.1 libclntsh.so in my case)
None of this is documented anywhere, which is quite unbelievable and quite frustrating. I spent over 3 hours yesterday with failed builds because I didn't know to create a soft link.
I think it may be the sudo has no access to get ORACLE_HOME.You can do like this.
sudo visudo
modify the text add
Defaults env_keep += "ORACLE_HOME"
then
sudo python setup.py build install
Alternatively you can install the cx_Oracle module without the PIP using the following steps
Download the source from here https://pypi.python.org/pypi/cx_Oracle
[cx_Oracle-6.1.tar.gz ]
Extract the tar using the following commands (Linux)
gunzip cx_Oracle-6.1.tar.gz
tar -xf cx_Oracle-6.1.tar
cd cx_Oracle-6.1
Build the module
python setup.py build
Install the module
python setup.py install
This just worked for me on Ubuntu 16:
Download ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip') from Oracle web site and then do following script (you can do piece by piece and I did as a ROOT):
apt-get install -y python-dev build-essential libaio1
mkdir -p /opt/ora/
cd /opt/ora/
## Now put 2 ZIP files:
# ('instantclient-basic-linux.x64-12.2.0.1.0.zip' and 'instantclient-sdk-linux.x64-12.2.0.1.0.zip')
# into /opt/ora/ and unzip them -> both will be unzipped into 1 directory: /opt/ora/instantclient_12_2
rm -rf /etc/profile.d/oracle.sh
echo "export ORACLE_HOME=/opt/ora/instantclient_12_2" >> /etc/profile.d/oracle.sh
echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$ORACLE_HOME" >> /etc/profile.d/oracle.sh
chmod 777 /etc/profile.d/oracle.sh
source /etc/profile.d/oracle.sh
env | grep -i ora # This will check current ENVIRONMENT settings for Oracle
rm -rf /etc/ld.so.conf.d/oracle.conf
echo "/opt/ora/instantclient_12_2" >> /etc/ld.so.conf.d/oracle.conf
ldconfig
cd $ORACLE_HOME
ls -lrth libclntsh* # This will show which version of 'libclntsh' you have... --> needed for following line:
ln -s libclntsh.so.12.1 libclntsh.so
pip install cx_Oracle # Maybe not needed but I did it anyway (only pip install cx_Oracle without above steps did not work for me...)
Your python scripts are now ready to use 'cx_Oracle'... Enjoy!
This worked for me
python -m pip install cx_Oracle --upgrade
For details refer to the oracle quick start guide
https://cx-oracle.readthedocs.io/en/latest/installation.html#quick-start-cx-oracle-installation
If you are trying to install in MAC , just unzip the Oracle client which you downloaded and place it into the folder where you written python scripts.
it will start working.
There is too much problem of setting up environmental variables.
It worked for me.
Hope this helps.
Thanks
Try to reinstall it with the following code:
!pip install --proxy http://username:windowspwd#10.200.72.2:8080 --upgrade --force-reinstall cx_Oracle
If you require to install a specific version of cx_Oracle, like 7.3 which was the last version with support for Python 2, you can do the following:
python -m pip install cx_Oracle==7.3