0

I'm attempting to use the following Python package:

https://github.com/amadeus4dev/amadeus-python

I have installed it as a global package via the pip3 install amadeus command and can see that it has been installed correctly, as reported by pip3 list

Despite it being installed, I am receiving the following error when trying to import it into a Django view:

Unable to import 'amadeus'pylint(import-error)

Troubleshooting

  • Uninstalled the package and reinstalled using sudo pip3 install amadeus
  • Uninstalled the package and reinstalled using python3 -m pip install amadeus
  • Checked that the package has been installed within a directory in my system path.

I'm currently all out of ideas for why it won't work for me and would be grateful if somebody had any ideas?

Thank you!

Tjm92
  • 167
  • 2
  • 19
  • Does this answer your question? [PyLint "Unable to import" error - how to set PYTHONPATH?](https://stackoverflow.com/questions/1899436/pylint-unable-to-import-error-how-to-set-pythonpath) – Grace Nov 10 '20 at 20:36
  • No, the package is installed here: /usr/local/lib/python3.8/dist-packages and my python path includes: ['', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/home/x/.local/lib/python3.8/site-packages', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages'] – Tjm92 Nov 10 '20 at 20:46

2 Answers2

0

you need to make sure that your PYHONNPATH includes you site packages.
best way to do so is by activating some virtual environment using source /path-to-venv/bin/activate

if that still doesn't work create a pylint configuration file and add the following:

[MASTER]
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"

what it does is while initing the hook, execute that python code to dynamically add the site_packages directory to your sys.path.

lastly, if you use VSCode, refer to this for best IDE integration: https://code.visualstudio.com/docs/python/environments#_choosing-an-environment

select your interpreter and that would be used with pylint plugin

Hagai Kalinhoff
  • 606
  • 3
  • 10
  • Thanks for your answer - as mentioned above, I have installed everything globally and not within a virtual environment. The PYTHONPATH includes where the package is installed and so I'm not sure what is the problem here. – Tjm92 Nov 10 '20 at 21:18
  • 1
    using virtual environments is indeed a _best-practice_ way of work, it might very well solve your issue. it might be due to the fact that you run on Debian system (or any derivatives such as Ubuntu). without regards to that, the fact is that `pylint` cant find the import and not python itself, that suggest that `pylint` does not know of the proper packages. open a virtual env is as easy as `python3 -m venv my-virtual-env` and then `source my-virtual-env/bin/activate` to use and then of course `pip3 install amadeus`. give it a go – Hagai Kalinhoff Nov 10 '20 at 22:05
  • Thanks again for your further comment. I have just tried installing and activating a virtual environment with amadeus - unfortunately the issue persists. I am running on Ubuntu currently via Windows Subsystem for Linux. Regarding your previous comment, where should I place the pylint configuration file, and do I need to do anything with it once created? Thank you – Tjm92 Nov 10 '20 at 22:21
  • 1
    you simple need to put it there as `pylint` searches for a configuration file before it runs. the configuration file also allows you to specify any rules you want or ignore the one you don't want. put the configuration file at your root directory (AKA top level project directory) with name `.pylintrc`. also checkout this page to see other options and more about the rules you can specify https://docs.pylint.org/en/1.6.0/run.html – Hagai Kalinhoff Nov 10 '20 at 22:41
  • Thank you! Unfortunately the configuration file didn't seem to work either, it flagged up some other errors (I believe erroneously) and the original one persisted. – Tjm92 Nov 10 '20 at 22:57
0

I managed to resolve this issue by reinstalling Python onto my Linux WSL by following the instructions here:

https://learn.microsoft.com/en-us/windows/wsl/install-win10

Tjm92
  • 167
  • 2
  • 19