pigpio icon indicating copy to clipboard operation
pigpio copied to clipboard

Running pigpio on virtual environment

Open craver2000 opened this issue 7 years ago • 4 comments

Hi, I wanted to ask if it is possible to use pigpio in a virtual environment?

Running the servo demo script worked for me in a non-virtual environment with the command sudo python servo_demo.py When I activated the virtual env and proceeded with the same installation and activation steps, I am likewise able to use the demo script with the same command.

However, the problem arise if I leave out sudo in my bash commands (i.e. python myscript.py ) since using the command sudo python myscript.py would render another module of this script unavailable in the virtual environment.

The error message when I used the non-sudo command goes: `Traceback (most recent call last): File "my_script.py", line 13, in import pigpio ImportError: No module named pigpio

I suspect the problem lies in the process of installation as I had to use sudo make install in one of the steps. I think I have to install via an alternative method that avoids global installation i.e. sudo. My understanding is that only pip can install packages into a virtualenv (from Pypi) (v.s. sudo which leads to global installation). Is there a way that I can install pigpio into a virtual environment? I appreciate any advice on how I can run pigpio module without using 'sudo' in a virtual environment.

craver2000 avatar Dec 10 '17 10:12 craver2000

Need a Python expert to assist with this question.

guymcswain avatar Jan 02 '20 18:01 guymcswain

While it would be nicer if the pigpio.py was packaged on PyPI for pip-assisted installation, it's actually very easy to install pigpio.py yourself. Just copy it into your venv's site-packages. You can find these under {sys.prefix}/lib/pythonX.X/site-packages, and to get at the prefix just run

python -c 'import sys; print(sys.prefix)'

dir-ableton avatar Mar 08 '20 17:03 dir-ableton

Ben Nuttall maintains a pigpio version on PyPy.

https://pypi.org/project/pigpio/

I do not understand how this is relevant to virtual environments.

joan2937 avatar Mar 08 '20 19:03 joan2937

It can be depending on the way the venv has been set up and the original poster has set it up and installed pigpio. There is for example the option to isolate venvs from system-installed packages, and that could have come into play here.

dir-ableton avatar Mar 09 '20 10:03 dir-ableton