To start, I've read the answer listed here, as well as tried to follow the instructions listed here, but the instructions were for an outdated or at least for a different version of Intellij, and the preexisting SO answer described the problem, but at least for me did not provide a solution. With that in mind:
I'm using IntellijIdea 2017.3 on Windows. I'm trying to create a basic web scraper in Python 3 (I'm very new at this, so I apologize in advance). To accomplish this, I want to use the library BeautifulSoup, which I've successfully installed using pip:
Here's what my project hierarchy looks like:
Of course, when I try to import beautifulsoup in scraper.py, it tells me there's no such module. The stack overflow post I linked to above tells me that this is because pip installs into \python\python36-32\lib\site-packages, but my Python interpreter is in another directory. But how do I fix this? Do I change the directory pip installs into, do I change where my project interpreter is? Is there a way to install python libraries directly through Intellij without using the outdated PyCharm instructions above? I'm new to python in general and very confused.
In case it helps, here's what my project settings, module settings, and SDK configuration look like:
You installed the module for the system-wide interpreter. However, you created a virtual environment for your IntelliJ project. In order to install modules from the command line in this virtual environment, you must activate it first. To do so, open the terminal in IntelliJ and run the activate command.
On Windows:
On Linux and mac:
Now you can run
Alternatively, you can manually type an import in a .py file:
IntelliJ will complain that there is no module named
bs4
. Move the cursor to this name and press Alt-Enter. There should be an option to install the module. Since IntelliJ is already aware of the virtual environment, it will install the module in the correct location so that your project will have it available.