Skip to content

[PyCharm] Introduction to Interpreter, pip and packages

PyCharm is the most well-known IDE of Python, PyCharm is used by many Python developers to develop projects. Today, I will introduce how we can add Python packages.


References

If you want to learn about Python, I recommend: [Python] Tutorial(1) Download and print “Hello World”.

If you want to install PyCharm as your IDE, you can refer to: PyCharm Installation Tutorial, A famous Python IDE


Interpreter

Python is a dynamic programming language, what we need is an Interpreter but not a Compiler.

In PyCharm, every project we created will have its virtual environment in the folder “venv“. There will be a newly established Interpreter, and there is nothing in it except the basic package.

The advantage of such a pure environment is that there is little conflict between the packages.

Press ctrl + alt + s, you can use the shortcut to open PyCharm settings page. In project’s Interpreter setting page, you will see:


Click the gear button in the upper right corner and select Add.


On the left, there are a variety of optional configurations, remote connections, virtual environments, conda environment establishment, and even WSL and Docker.

For the configuration of the remote environment, please refer to: [Python] Use PyCharm to connect to the Python interpreter of the remote server


pip

pip is a tool of the Python management suite, which is very convenient to use in command line.

Python2: pip install "package"
python3: pip3 install "package"

The above is the default usage method, if you want to adjust, you can also directly set the pip of Python3 to pip.

In PyCharm, we actually have a graphical interface to download the kit. (Of course, if you are accustomed to command line, there is actually a command line below that can be used, and the downloaded package will be installed directly in the virtual environment of the current project)

Remember the Interpreter interface just now? Open it with ctrl + alt + s, and then find the interface just now.


We pay attention to the two buttons “+” and “-” on the right.

You can see that there are already many Packages in my current project. If you want to remove a package, just select it and press the “-” on the right.

Then think about it the other way around, the “+” sign is to install the package, that is, there is no need to enter the pip command from the Command Line, and the system will automatically install it for us.

Click “+”:

We will see this screen, this screen will list all packages that can be installed, and the search box above allows us to actively search for the package we want.

If there is a specific version, for example, you don’t want to update some packages to the latest package (sometimes the latest version is not stable), you can also use the Specify version next to it:

Choose the package and version you want.

After selecting it, press “Install Package” and it will automatically install it for us.


Packages

Packages in Python are some libraries that others have developed for us, so that we can directly import them into our programs without “Reinventing the wheel“.

PyCharm will kindly remind you that the package like my chatterbot has been underlined, which means that there is no such package in my environment.

So I installed the ChatterBot package in the virtual environment of my current project in accordance with the teaching in pip just now. (By the way, ChatterBot also needs to install chatterbot-corpus to run smoothly)

You can see that my PyCharm has no red bottom line warning.

This is an official sample code, you can find it at https://pypi.org/project/ChatterBot/.

Run the code. In my case, I need to press Ctrl + Shift + F10 to execute it directly. My friend told me that it can be changed, but I haven’t tested it.

Execute:

Unzipping corpora\stopwords.zip.
Training ai.yml: [####################] 100%
Training botprofile.yml: [####################] 100%
Training computers.yml: [####################] 100%
Training conversations.yml: [####################] 100%
Training emotion.yml: [####################] 100%
Training food.yml: [####################] 100%
Training gossip.yml: [####################] 100%
Training greetings.yml: [####################] 100%
Training health.yml: [####################] 100%
Training history.yml: [####################] 100%
Training humor.yml: [####################] 100%
Training literature.yml: [####################] 100%
Training money.yml: [####################] 100%
Training movies.yml: [####################] 100%
Training politics.yml: [####################] 100%
Training psychology.yml: [####################] 100%
Training science.yml: [####################] 100%
Training sports.yml: [####################] 100%
Training trivia.yml: [####################] 100%

We can see that ChatterBot executes normally; it has trained quite a bit.

Leave a ReplyCancel reply

Click to Copy
Exit mobile version