Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Python see module installed via apt?

I'm trying to use Travis CI to run tests of my Python code.

My project needs dbus module and it's not available in PyPi, so I have to install it via apt.

Problem is that tests fail with ImportError: No module named 'dbus'. It's quite strange, because I can see in report about successful installation of required packages. Here is my .travis.yml and example of Travis log.

Do I do something wrong?

like image 412
Valery Ryaboshapko Avatar asked Oct 31 '22 17:10

Valery Ryaboshapko


1 Answers

From the travis log you posted, all your packages are being installed in a virtual environment.

The virtual environment is created in a clean state - so it does not have any links to system libraries, indeed it states so in the documentation:

CI Environment uses separate virtualenv instances for each Python version. System Python is not used and should not be relied on. If you need to install Python packages, do it via pip and not apt.

If you decide to use apt anyway, note that Python system packages only include Python 2.7 libraries on Ubuntu 12.04 LTS. This means that the packages installed from the repositories are not available in other virtualenvs even if you use the –system-site-packages option.

I believe it explains your problem:

  1. virtual environments are isolated and have no link to system packages.
  2. Even if you use apt, it is limited to Python 2.7, and you are trying to install a python3- package.
like image 58
Burhan Khalid Avatar answered Nov 15 '22 07:11

Burhan Khalid