0

I work on Ubuntu Xenial (16.04) with python3, I also installed anaconda.

I installed python3-gammu (with apt install python3-gammu or/and pip install python3-gammu) to test send SMS.

Just run python3 console and

>>> import gammu
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named 'gammu'


import sys
print(sys.path)

only return anaconda paths !

If I run

sudo find -iname gammu
…
./usr/lib/python3/dist-packages/gam
…

so if I add this path:

>>> sys.path.append('/usr/lib/python3/dist-packages/')
>>> import gammu

and it works !

Could you clarify this library path issue?

bcag2
  • 1,988
  • 1
  • 17
  • 31
  • You've already basically identified the problem: your module is installed somewhere that is not in Python's import path. – khelwood Mar 22 '18 at 09:33
  • it's a separate environment issue, when I run python3, it is anaconda environment: `Python 3.5.2 |Anaconda 4.2.0 (64-bit)`, so probably I should install python3-gammu with conda … but If I launch `conda install python3-gammu`, it returns `PackageNotFoundError: Packages missing in current channels` – bcag2 Mar 22 '18 at 09:33
  • Obviously `python3-gammu` is installed to your python dist but not in your `anaconda` env. This may be due to the use of `apt get` or `pip`. Please, check whether `pip` belongs to `anaconda` or by typing `which pip` to the terminal. – MaxPowers Mar 22 '18 at 09:55
  • @MaxPowers : it was probably with `apt` because `which pip` returns `…/anaconda3/bin/pip` and `pip install python3-gammu` doesn't find python3-gammu! – bcag2 Mar 22 '18 at 10:14

2 Answers2

1

just

export PYTHONPATH=$PYTHONPATH:/usr/lib/python3/dist-packages/

To keep it at next reboot, put this line in your ~/.bashrc :

# added by Anaconda3 4.2.0 installer
export PATH="/home/my_user_name/anaconda3/bin:$PATH"
export PYTHONPATH="/usr/lib/python3/dist-packages/:$PYTHONPATH"

to active new .bashrc, do not forget to run

source ~/.bashrc
bcag2
  • 1,988
  • 1
  • 17
  • 31
0

When you are trying to import any package it will check sys.path, which contains all paths of packages. If it find the package you want to import it will import it.

sorry for bad english...

Why use sys.path.append(path) instead of sys.path.insert(1, path)?

You may get clarity after seeing this ?

MaheshPVM
  • 158
  • 1
  • 13
  • Thanks, `virtualenv` (or `venv`) could probably solve my issue, but in my case I think the problem are linux python3 and anaconda3 is already in separate environments… and differents paths – bcag2 Mar 22 '18 at 10:28