I tried to install distribute or setuptools which has to be done prior to installing pip on the Raspberry Pi.
The command used was $ curl http://python-distribute.org/distribute_setup.py | python
However I got the following error. I can copy past the entire terminal script if requested.
[Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/test-easy-install-2082.pth'
Thanks for helping!
I have never using raspberry pi. But from the log can be seen it complain about cannot have permission to modify python package directory. You have to run pip install using root privilege.
This answer is based on what ever operating system you have but one that is specifically Linux based like raspbian you should open up terminal and type in chmod +x file path here. Also for this to work you should be inside where ever the file is stored when you run chmod +x etc... /Desktop/python/ for example would work.
try
sudo curl http://python-distribute.org/distribute_setup.py | python command
some permisssions problem are resolved like this. I'm not sure if this works.
Related
I have a python script called main.py that imports RPi.GPIO library using import RPi.GPIO as GPIO
When I run the script using python3 main.py I get an error that states RPi.GPIO was not found. If I run main.py using sudo python3 main.py then everything runs fine.
I installed RPi.GPIO using a tar.gz file. I copied it to my /home/pi/work directory and extracted the tarball in the same directory. I then changed to the extracted directory and installed RPi.GPIO using sudo python3 setup.py install.
As I don't normally use linux I don't fully understand the permissions which I am sure is what is causing this issue. I am guessing that since I installed using sudo that the package is only available to the sudo user. The problem is I am starting this program from rc.local file and the main.py script wont run at startup with the RPi.GPIO import statement. If I remove the import statement it starts as expected. Below is the code in the rc.local file that starts the program su -l pi -c '/usr/bin/python3 /home/pi/Work/main.py &' I tried changing su to sudo but that did not work.
Is there a different way I can install RPi.GPIO or change the rc.local script to get this working? Also FYI my pi has no internet connection so I can't use APT-GET to uninstall or install the package.
Also just in case some of you wonder if the package installed properly it has. If I start python with sudo python3 I get >>>. I then type import RPi.GPIO as GPIO I get >>> again. Then I type GPIO.VERSION it displays the correct version I installed. Any help would be appreciated.
UPDATE
I did not create the code for the rc.local file and looked a little closer at it. The statement su -l pi -c '/usr/bin/python3 /home/pi/Work/main.py &' I found out changes the user from root to pi and executes the script under the pi user. So I tried changing the statement to su -l sudo -c '/usr/bin/python3 /home/pi/Work/main.py &' thinking that since I can run the main.py by using sudo python3 main.py that changing user from pi to sudo in the rc.local file would execute the file as sudo. It still does not work. I then tried removing the su command from the rc.local command and ran like this /usr/bin/python3 /home/pi/Work/main.py & but this also didn't work. Does anyone have any suggestions on how I can get this to work?
Try to write bash script with sleep before running python script and put it into rc.local
#!/bin/sh
sleep 5
python python_script.py &
Don't forget to make script executable: chmod 755 yourscript.sh
For developing in Python, on Linux or any OS, one would almost always use a virtualenv, one for each python project I want to develop.
A virtualenv is easy to set up, and once activated, you can execute your pip install commands without using sudo. Try setting up a virtualenv and installing GPIO via pip.
Even if you don't set up a virtualenv to help with package management for your Python project, you can still use pip to install GPIO, but you'll face the permission issues you're dealing with now.
But, you're in luck! GPIO is already installed on Raspbian. Open up the Terminal and type python. Once you're in the Python interpreter, type import RPi.GPIO. If you get an error, there is a genuine issue with your installation, but it can be easily overcome by using a virtualenv. It may help to know which is your default python, with python --version.
Pip is conceptually similar to the apt package manager you've probably used with your Raspberry Pi to install other pieces of software. It's a package manager for Python, basically a registry of libraries you can install instantly on the command line.
The command line is your friend on an RPi, especially when it comes to developing original software.
Good luck!
I tried installing anaconda on the Raspberry Pi using the 32 bit installer in their webpage. After finding out where the file is located I put the command
bash ~/Downloads/Anaconda3-5.1.0-Linux-x86.sh
Once the installation location was picked, I got the following error.
installing: python-3.6.4-hc3d631a_1 ...
/home/pi/Downloads/Anaconda3-5.1.0-Linux-x86.sh: line 373: /home/pi/anaconda3/pkgs/python-3.6.4-hc3d631a_1/bin/python: cannot execute binary file: Exec format error
Any idea how to install anaconda?
The problem is that you try to install Anaconda for x86 CPUs (such as Intels) whereas the Raspberry Pi has an ARM based CPU. You need to use the following install script:
wget http://repo.continuum.io/miniconda/Miniconda3-latest-Linux-armv7l.sh
chmod +x Miniconda3-latest-Linux-armv7l.sh
./Miniconda3-latest-Linux-armv7l.sh
You may check the file permissions such
sudo chmod 775 Anaconda3-5.1.0-Linux-x86.sh
Alternatively you may just run with ./Anaconda3-5.1.0-Linux-x86.sh
I was hoping someone might be able to provide a resource that will help me install python 3.6.0 on a shared hosting account at Bluehost. I’ve tried using the documentation for python 2.7 but have been unsuccessful to date. The current state of the machine now is if I run python –V it says 2.6.6 . If, however I place:
export PATH=$HOME/python/Python-3.6.0/:$PATH
in the .bashrc file in my home directory and then run python –V it says 3.6.0 However I am unable to get pip to work. I also noticed that during the python setup procedure permission was denied on a number of files.
I am really at a lost as there seems to be very little documentation for how to do this on a shared hosting environment. Your help would be greatly appreciated.
here's a link to the instructions I followed python
I thought pip would be installed as it said pip 9.0.2 was installed but when I try to run it it say cxommand not found. When I tried easy_install pip I got back the following error message:
[Errno 30] Read-only file system: '/usr/lib/python2.6/site-packages/test-easy-install-13141.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/usr/lib/python2.6/site-packages/
You cannot install the package because it is trying to install them in the system directory, and you do not have write access.
If you can, use a virtualenv. Of course this requires virtualenv be installed.
Put the virtualenv somewhere you have write access to. For example, use these instructions.
Enter the following commands to download and extract Python
3.6 to your hosting account.
mkdir ~/python
cd ~/python
wget http://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
tar zxfv Python-3.6.0.tgz
find ~/python -type d | xargs chmod 0755
cd Python-3.6.0
Install Python
Once extracted you can use the following commands to
configure and install Python.
./configure --prefix=$HOME/python
make
make install
Modify the .bashrc
For your local version of python to load you will need to add
it to the .bashrc file.
vim ~/.bashrc
Press i
Enter:
export PATH=$HOME/python/Python-3.6.0/:$PATH
export PYTHONPATH=$PYTHONPATH:$HOME/python/python3.6/site-packages/
Write the changes (press ESC) and close vim:
:wq
Press Enter
source ~/.bashrc
Now to use pip:
python -m pip install package-of-interest
You could also ask the system administrator to install the package for you. This might be the only real option if virtualenv hasn't been installed. Ask the administrator to install virtualenv.
I'm trying to run some python code with the sudo command, but every time I do it, it gives me an Import error. However, if I run, say, import numpy in terminal it gives me no errors. Also, if I build a code with several Imports and then run it without the sudo command, it gives me no errors and the code runs flawlessly. I already added Defaults env_keep += "PYTHONPATH" to the sudoers folder, so that's not the problem. I installed Anaconda3, so maybe that's useful information?
I'm running GNOME Ubuntu 16.04.1 LTS. And kernel version 4.4.0-59-generic.
I'm sorry, I'm very new at this, but I'm learning.
I ran which python and then I ran sudo which python and they gave me different directories.
sudo which python gave me usr/bin/python which python gave me home/user/anaconda3/bin/python
I tried running sudo ./anaconda3/envs/ml/bin/python doc.py but now it says that it can't find the file.
I'm running it with sudo because I need the permission for docker to work.
EDIT: trying sudo -E instead of sudo yields the same error.
The problem you have is that sudo does not follow the usual PATH order when looking at an executable: it searches the system directories first. This is written in the man sudo:
SECURITY NOTES
sudo tries to be safe when executing external commands.
To prevent command spoofing, sudo checks "." and "" (both denoting current directory) last when searching for a command in the
user's PATH (if one or both are in the PATH). Note, however, that the actual PATH environment variable is not modified and is passed
unchanged to the program that sudo executes.
So, to fix this you have to make sure that the command you give to sudo cannot match a system executable, i.e. specify the absolute path:
sudo /home/user/anaconda3/bin/python
A general command that should work is:
sudo "$(which python)"
This is because which python is executed before sudo, and its output is passed as an argument to sudo. However sudo by default does not perform any "shell-like" setup, and may restrict the environment, so you may consider using the -E or -i flags to make sudo pass the environment untouched and do the proper shell setup.
I know this may be the most silliest questions to be asked but i'm suddenly not able to open python from terminal.
I have python 2.7 installed on ubuntu 14.04 box, but now when i fire python on my command line i get the error
aman#L-JZCHG32:~$ python
The program 'python' is currently not installed. You can install it by typing:
sudo apt-get install python-minimal
I have tried reinstalling python
sudo dpkg -P python2.7
sudo apt-get install python2.7
but it still wont work. Can somebody suggest me what went wrong and how can i correct it.
Thanks.
It seems you've probably corrupted your PATH variable. Try /usr/bin/python in the terminal. If that works, you'll need to fix your PATH variable.
A quick fix would be export PATH=/usr/bin:$PATH but there's probably something not quite right with the whole path variable at the moment, which would be worth further examining.