I'm learning Python and working on a current tutorial. From a console I can open python and run the code below. However, I'm not able to run this in Spyder and PyCharm. When I try to use this code in those programs or any snipped involving tld, it returns "no module named 'tld'".
I've spent the past hour on google and this site trying resolutions for modules not being found, to no avail. Side note, I can import tkinter no issue, so I have imported other modules before. This is the first one that hasn't worked. I know tld is installed obviously, as it works if I just go into a python console from a terminal. PyCharm is using python 3.6, which is the same version I'm running from a terminal. Spyder is using 3.5 (because I can't get it to use 3.6). FWIW, I'm on Fedora 25. Stumped.
from tld import get_tld def get_domain_name(url): domain_name = get_tld(url) return domain_name print(get_domain_name("http://www.reddit.com"))
python / tld output:
$ python Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> exit() [****@Unknown ~]$ pip show tld Name: tld Version: 0.9.1 Summary: Extract the top level domain (TLD) from the URL given. Home-page: https://github.com/barseghyanartur/tld Author: Artur Barseghyan Author-email: firstname.lastname@example.org License: MPL 1.1/GPL 2.0/LGPL 2.1 Location: /home/****/anaconda3/lib/python3.6/site-packages Requires: six
Two things you have to check:
- Are you using the correct Python version?
- Is the package installed?
First we check the version within python
import sys print(sys.version_info)
Is the python version what you are expecting? Is it possible that you have multiple python installations? If this won't work then you might be using python 2. Else check if your python version has the package installed (this is done in your console/terminal):
pip show tld
If you have multiple python installations they won't share the packages. Therefore you have to install them by hand. You can do this by calling the pip of the python installation by hand (go into the folder and run the programm).
If you use virtual environments then every environment will need his own installation. I personally recommend to use a tool like anaconda navigator to do that.
Note: pycharm can use multiple python environments/installations. Make sure that every script is using the right one.