Install Python-Dbus in virtualenv - python

I am running an application in a virtual environment that needs access to DBus (to interact with the Network Manager, mainly).
I tried to install Dbus-Python with easyinstall and pip, but both fail.
When I try to do this:
(myvirtualenv)borrajax#borrajax-computer:~/Documents/Projects/VirtualEnvs/current_env$ bin/pip install dbus-python
Pip yells at me with:
Downloading/unpacking dbus-python
Downloading dbus-python-1.1.1.tar.gz (596kB): 596kB downloaded
Running setup.py egg_info for package dbus-python
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '/home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python/setup.py'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
IOError: [Errno 2] No such file or directory: '/home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python/setup.py'
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /home/borrajax/Documents/Projects/VirtualEnvs/current_env/build/dbus-python
Storing complete log in /home/borrajax/.pip/pip.log
I have had some issues with the python dbus bindings and their "accessibility" from my Python modules in the past, so I don't really know what may be the best way to set Dbus-Python in a virtual environment. Has anyone successfully achieved this? Or does anyone have an idea on how to do this?

Go to your Venv follow this 2 steps :
sudo apt-get install libdbus-glib-1-dev libdbus-1-dev
pip install dbus-python
verify with:
pip freeze
if installed properly you will see: dbus-python==1.2.8

My suggestion is to install the system package for the Python DBUS bindings and then create the virtualenv with the --system-site-packages command line option to enable access to the system-wide Python packages (including the dbus package) from the activated virtualenv. For example on Debian/Ubuntu (or a derived distribution):
$ sudo apt-get install python-dbus
$ virtualenv --system-site-packages dbus-venv
To use the built in Python 3 venv module instead of virtualenv:
$ sudo apt-get install python-dbus
$ sudo apt-get install python3-venv
$ python3 -m venv --system-site-packages my_venv

When pip tries to install a package, it looks for setup.py, which dbus-python doesn't have, so you'll have to download the source and compile it manually. Shouldn't be too hard:
PYTHON=python3.3 ./configure --prefix=/tmp/dbus-python
make
make install
then you can move the compiled files to your virtualenv.
edit: starting with dbus-python-1.2.2 (released 2016-02-22) dbus-python has a setup.py, so pip should be able to install it

Another workaround is to just manually copy the dbus files/libraries directly to your virtualenv:
cp -r /usr/lib/pythonX.X/{site or dist}-packages/dbus myvirtenv/usr/lib/pythonX.X/site-packages/
cp -r /usr/lib/pythonX.X/{site or dist}-packages/_dbus_*.so myvirtenv/usr/lib/pythonX.X/site-packages/

The OP appears to have opened a ticket on freedesktop.org for this, which remains open; however there is a patch attached to that ticket that could be applied to most any version of python-dbus and then repackaged as a new tarball.

#TheMeaningfulEngineer thank so much, i have being having a few problem to install dbus through pip and that was what i needed i hope you have a good day wherever you are ;)
to check if there is in local - sudo apt list --installed | grep package-name
sudo apt-get install libdbus-glib-1-dev libdbus-1-dev
and after this line I did install dbus and networkmanager without any errors
This is exactly what I did, and before that I checked out all my dbus version and networkmanager after do what #TheMeaningfulEngineer said is working.

For Python as dbus-python is now obsolete, you should be using pydbus:
pip install pydbus
This have worked for me.

Related

Python cannot install PyGObject

I try install pygobject by pip
pip install --user PyGObject
but I doesn't work:
Collecting PyGObject
Using cached pygobject-2.28.3.tar.bz2
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 20, in <module>
File "C:\Users\A\AppData\Local\Temp\pip-build-phby_jwb\PyGObject\
setup.py", line 272
raise SystemExit, 'ERROR: Nothing to do, gio could not be found and is
essential.'
^
SyntaxError: invalid syntax
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\A\AppData\Local\Temp\pip-build-phby_jwb\PyGObject
My python version v3.5.0:374f501f4567,
Now I work on windows 7
For windows
Go to http://www.msys2.org/ and download the x86_64 installer
Follow the instructions on the page for setting up the basic environment
Run C:\msys64\mingw32.exe - a terminal window should pop up
Execute pacman -Suy
Execute pacman -S mingw-w64-i686-gtk3 mingw-w64-i686-python3-gobject
To test that GTK 3 is working you can run gtk3-demo
Copy the hello.py script you created to C:\msys64\home\<username>
In the mingw32 terminal execute python3 hello.py - a window should appear.
For ubuntu / Debian
Installing the system provided PyGObject:
Open a terminal
Execute sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0
Change the directory to where your hello.py script can be found (e.g. cd Desktop)
Run python3 hello.py
Installing from PyPI with pip:
Open a terminal and enter your virtual environment
Execute
sudo apt install libgirepository1.0-dev gcc libcairo2-dev pkg-config python3-dev gir1.2-gtk-3.0
Execute pip3 install pycairo to build and install Pycairo
Execute pip3 install PyGObject to build and install PyGObject
Change the working directory to where your hello.py script can be found
Run python3 hello.py
You can read more here
Since February 2017, you can install pygobject directly through pip: pip install pygobject. It requires some packages to be installed though.
Before that, it took a while, but it was possible to install pygobject with pip, since this commit.
pygobject wasn't on pypi though, so you had to specify the git or tarball URL:
git+https://git.gnome.org/browse/pygobject
https://download.gnome.org/sources/pygobject/3.22/pygobject-3.22.0.tar.xz
The latter only works with pygobject 3.22+, which should have happenned around mid-september 2016. (3.21.1 should be the first pip-installable development release)
Upstream PyGObject just does not support this. See the PyGObject win32 project or the MSYS2 project to get it easily.
I'll just add what I've been using to make this work seamlessly in various projects.
It uses GNU Make, by providing a venv target one can use as a dependency to other targets to ensure a properly created virtual environment.
The venv target itself depends on a, albeit configurable, requirements.txt; the standard python requirements file.
A target test is include as an example of how one would use this.
The trick is to create a symlink to the installed system package. ln -s ${DIST_PACKAGES}/gi ${VENV_NAME}/lib/python${PYTHON_VER}/site-packages/gi, where $DIST_PACKAGE is the location of the python installed libraries on your system.
For those not familiar with make. Create a file named Makefile in the root of your project, copy the contents bellow, and issue the command make configure && make venv.
Makefile
# directory to store virtual environment
VENV_NAME=venv
# python runtime version
PYTHON_VER=3.6
# python executble
PYTHON=${VENV_NAME}/bin/python${PYTHON_VER}
# python local libraries location
DIST_PACKAGES=/usr/lib/python3/dist-packages
# pip requirements file
REQUIREMENTS=requirements.txt
configure: ## Install required debian packages.
sudo apt-get -y install python${PYTHON_VER} python3-pip libgirepository1.0-dev
python3 -m pip install virtualenv pygobject
make venv
venv: ## Recreates the virtual environment if needed.
venv: $(VENV_NAME)/bin/activate
$(VENV_NAME)/bin/activate: ${REQUIREMENTS}
test -d $(VENV_NAME) || virtualenv -p python${PYTHON_VER} $(VENV_NAME)
${PYTHON} -m pip install -U pip
${PYTHON} -m pip install -r ${REQUIREMENTS}
ln -s ${DIST_PACKAGES}/gi ${VENV_NAME}/lib/python${PYTHON_VER}/site-packages/gi
touch $#
test: ## Runs the test suite.
test: venv
$(PYTHON) -m pytest tests

ImportError: No module named virtualenv

I am using Django 1.3.7 and python 2.7.6 on windows7
I got an error when I executing my manage.py in this line of code
import shutil, sys, virtualenv, subprocess
amd running it, I got this error
C:\Django-Proj\>python manage.py update_ve
Traceback (most recent call last):
File "manage.py", line 4, in <module>
import shutil, sys, virtualenv, subprocess
ImportError: No module named virtualenv
Does anyone have an Idea about my case?
Install virtualenv using pip install virtualenv.
If you have it already installed, try reinstalling it by removing it with pip uninstall virtualenv and then reinstalling it.
Good Luck.
I had to install virtualenv with the -H flag to set HOME variable to target user's home dir.
sudo -H pip install virtualenv
I think the problem is you need sudo to globally install virtualenv.
> pip install virtualenv
Could not find an activated virtualenv (required).
> sudo pip install virtualenv
Downloading/unpacking virtualenv
...
But this creates files readable only by root (depending on the umask).
In this case, uninstalling/reinstalling may not always help.
You can check with ls -la /usr/local/lib/python2.7/dist-packages/virtualenv.py (replacing 2.7 with whatever version you have or are targeting).
My solution was simply:
sudo chmod -R o+rX /usr/local/lib/python2.7
Use pip3 instead of pip. I had the same issue and pip3 worked for me.
$ pip3 install virtualenv
$ virtualenv venv --python=python3
Try
python3 -m pip uninstall virtualenv
python3 -m pip install virtualenv
I just ran into this same problem. I had to pip uninstall virtualenv as a user with admin rights, then pip install virtualenv as a normal user. I think it's some kind of permissions issue if you installed virtualenv under admin rights.
>virtualenv
ImportError: No module named 'virtualenv'
>pip uninstall virtualenv
PermissionError: [Errno 13] Permission denied:
>sudo pip uninstall virtualenv
Successfully uninstalled virtualenv-15.1.0
>pip install virtualenv
Collecting virtualenv
>virtualenv
Options:
Bingo!
I had the same problem when I created my virtualenv via pycharm and installed requirements with pycharm.
After trail and error , I found that installed requirements are not taken into account by the virtualenv.
The solution is to reinstall all requirements once you have activated your virtualenv:
venv\scripts\activate
python -m pip install -r YourRequirements.txt
Next time I'd better create my virtualenv directly with command line
Got this error when using the ansible pip module automating some pip installs on my localhost.
fatal: [localhost]: FAILED! => {"changed": false, "cmd": ["/opt/bin/virtualenv", "--system-site-packages", "-p/usr/bin/python3", "/opt/venv/myenv"], "msg": "\n:stderr: /usr/bin/python3: No module named virtualenv\n"}
Uninstalling virtualenv python3 -m pip uninstall virtualenv did show virtualenv was installed here /home/ubuntu/.local/bin/virtualenv.
In the ansible task specify the virtualenv_command:
- name: install requirements file
pip:
virtualenv_command: "/home/{{whoami.stdout}}/.local/bin/virtualenv"
virtualenv: "/home/{{whoami.stdout}}/.venv/{{item.env.virtualenv}}"
requirements: "/home/{{whoami.stdout}}/git/{{item.env.requirements_txt}}"
virtualenv_site_packages: yes
when: req_stat.stat.exists
For mac os the issue was with virtualenv. This is because the folder virtualenv did not exist.
This worked well
python3 -m venv env

HOW TO INSTALL pyinotify TO python3.3 ENVIRONMENT?

I compiled Python 2.7 and Python 3.3.3 in my VPS.
The compilation of Python 2.7 is:
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
tar -jxvf Python-2.7.3.tar.bz2
cd Python-2.7.3
./configure
make
make install
The compilation of Python 3.3 is:
wget http://python.org/ftp/python/3.3.3/Python-3.3.3.tar.bz2
tar -jxvf Python-3.3.3.tar.bz2
cd Python-3.3.3
./configure --prefix=/usr/local/python-3.3.3
make
make install
ln -s /usr/local/python-3.3.3/bin/python3.3 /usr/local/bin/python3.3
as3:/usr/local/python-3.3.3/lib/python3.3# python3.3 letterpress.py ~/letterpress/press_folder
Traceback (most recent call last):
File "letterpress.py", line 27, in
import pyinotify
ImportError: No module named 'pyinotify'
as3:/usr/local/python-3.3.3/lib/python3.3# pip install pyinotify
Requirement already satisfied (use --upgrade to upgrade): pyinotify in /usr/local/lib/python2.7/site-packages/pyinotify-0.9.4-py2.7.egg
Cleaning up...
as3:/usr/local/python-3.3.3/lib/python3.3#
In the above, pyinotify is installed to Python 2.7 environment, now how can I install pyinotify to Python 3.3 environment?
One way is to install a second copy of pip using your Python 3 instance. Then use that pip to install a copy of pynotify for Python 3.
I solved it myself.
Check here: https://github.com/seb-m/pyinotify
git clone https://github.com/seb-m/pyinotify.git
cd pyinotify
python3.3 setup.py install
(thus I can install pyinotify to python3.3 environment successfully)
or:
wget http://python-distribute.org/distribute_setup.py
python3.3 distribute_setup.py
it will show:
...
Installing easy_install script to /usr/local/python-3.3.3/bin
Installing easy_install-3.3 script to /usr/local/python-3.3.3/bin
...
/usr/local/python-3.3.3/bin/easy_install-3.3 pyinotify
(thus I can install pyinotify to python3.3 environment successfully)

install python reddit api wrapper module

I have downloaded the source in a zip file. I then moved it to /Library/Python/2.6/site-packages/mellort-reddit_api-2d91358. I have been trying to install it with: python setup.py install. This has not worked. I then tried to install it with python /Library/Python/2.6/site-packages/mellort-reddit_api-2d91358/setup.py install, but that would not work as well.
On both occasions it said:
Traceback (most recent call last):
File "/Library/Python/2.6/site-packages/mellort-reddit_api-2d91358/setup.py", line 9, in <module>
open('reddit/__init__.py').read()).group(1)
IOError: [Errno 2] No such file or directory: 'reddit/__init__.py'
I think it cannot find the:
reddit/__init__.py
I have only tried putting the file in the python 2.6 folder.
Any thoughts? If you could provide step by step instructions I would be extremely happy.
I am using mac if that makes a difference.
If you have used this module before (found at https://github.com/mellort/reddit_api) how did you deal with this issue?
You can install it through pip:
sudo apt-get install python-pip python-dev build-essential
sudo pip install reddit -U
update after OP's comments:
for a mac you can do this:
sudo easy_install pip
sudo pip install reddit -U
more info on how to install pip on a mac can be found here.

How to install mechanize for Python 2.7?

I saved mechanize in my Python 2.7 directory. But when I type import mechanize into the Python shell, I get an error message that reads:
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import mechanize
ImportError: No module named mechanize
using pip:
pip install mechanize
or download the mechanize distribution archive, open it, and run:
python setup.py install
Try this on Debian/Ubuntu:
sudo apt-get install python-mechanize
You need to follow the installation instructions and not just download the files into your Python27 directory. It has to be installed in the site-packages directory properly, which the directions tell you how to do.
I dont know why , but "pip install mechanize" didnt work for me . easy install worked anyway . Try this :
sudo easy_install mechanize
Here's what I did which worked:
yum install python-pip
pip install -U multi-mechanize
sudo pip-2.7 install mechanize
You need the actual package (the directory containing __init__.py) stored somewhere that's in your system's PYTHONPATH. Normally, packages are distributed with a directory above the package directory, containing setup.py (which you should use to install the package), documentation, etc. This directory is not a package. Additionally, your Python27 directory is probably not in PYTHONPATH; more likely one or more subdirectories of it are.
install dependencies on Debian/Ubuntu:
$ sudo apt-get install python-pip python-matplotlib
install multi-mechanize from PyPI using Pip:
$ sudo pip install -U multi-mechanize
You need to install the python-setuptools package:
apt-get install python-setuptools on Debian-ish systems
yum install python-setuptools on Redhat-ish systems
Use sudo if applicable
It seems you need to follow the installation instructions in Daniel DiPaolo's answer to try one of the two approaches below
install easy_install first by running "easy_install mechanize", or
download the zipped package mechanize-0.2.5.tar.gz/mechanize-0.2.5.zip and (IMPORTANT) unzip the package to the directory where your .py file resides (i.e. "the resulting top-level directory" per the instructions). Then install the package by running "python setup.py install".
Hopefully that will resolve your issue!
pip install mechanize
mechanize supports only python 2.
For python3 refer https://stackoverflow.com/a/31774959/4773973 for alternatives.

Categories