pip installしたはずなのにImport errorを解決する方法


$ pip install tweepy --user
Requirement already satisfied: tweepy in /home/ubuntu/.local/lib/python3.7/site-packages (3.8.0)
Requirement already satisfied: six>=1.10.0 in /usr/lib/python3/dist-packages (from tweepy) (1.11.0)
Requirement already satisfied: requests-oauthlib>=0.7.0 in /home/ubuntu/.local/lib/python3.7/site-packages (from tweepy) (1.3.0)
Requirement already satisfied: PySocks>=1.5.7 in /home/ubuntu/.local/lib/python3.7/site-packages (from tweepy) (1.7.1)
Requirement already satisfied: requests>=2.11.1 in /usr/lib/python3/dist-packages (from tweepy) (2.18.4)
Requirement already satisfied: oauthlib>=3.0.0 in /home/ubuntu/.local/lib/python3.7/site-packages (from requests-oauthlib>=0.7.0->tweepy) (3.1.0)

してるのに


$ python3 followback_unfollow.py
Traceback (most recent call last):
  File "followback_unfollow.py", line 3, in <module>
    import tweepy
ModuleNotFoundError: No module named 'tweepy'
ubuntu@ip-192-168-1-89:~/my-app$ 

解決するには

$ export PYTHONPATH=$PYTHONPATH:/home/ubuntu/.local/lib/python3.7/site-packages

して

$ source ~/.bashrc

する。

$ python3 followback_unfollow.py
Works!!!
参考

pip installしたはずなのにImport errorと言われた場合
pipでインストールしたパッケージの場所を調べる