In Getting Started with Python on Ubuntu we set up a Ubuntu desktop to make use of Anaconda and the Conda package and environment management system to quickly and easily create development environments for your Artificial Intelligence and Machine Learning projects.
PyCharm is an Integrated Development Environment (IDE) specially designed for Python. Anaconda is a Python distribution that includes the standard Python interpreter packaged with a smorgasbord of additional Python modules for scientific computing. There is nothing preventing you from using both! PyCharm provides some interesting integration for virtualenv s and pip, but the Anaconda Python distribution seems to prefer using its own conda tool for both activities. Is there a relatively simple/painless way to be able to use conda in conjunction with PyCharm?
In this post we’ll expand on this and walk-through the process of creating a new python project making use of Conda in Pycharm – The Python IDE for Professional Developers.
Ensuring you have Anaconda and Conda installed Ubuntu desktop machine and you have installed Pycharm
Pycharm Anaconda Environment
Conda install linux-64 v2019.3; To install this package with conda run: conda install -c fwaters pycharm. You can't find anaconda python in your console at first.Click Configure Interpreters in blue. Click the little gear under reset in blue (right + up corner), and chose 'add local'. Point to your python in anaconda.
Starting a new Conda project in Pycharm
Open Pycharm and select File -> New Project this show the new project Dialog box. In this example we will simply create a Pure Python project
If it is not expanded , then expand the Project Interpreter:
The select the New Environment using option button which will enable the drop down selection box and you should be able to select Conda
Ensuring you select the appropriate path you would like your new project and environment created you can then select the Create button.
Pycharm will now create the project for you.
If you would like to configure an existing project check out Configuring a Conda Environment
Your new environment should now be prepared and you are now ready to start coding.
Install Project Dependencies
In order to start developing an application we will need to install whatever dependencies we need for the project. In this example we are just going to develop a simple application which will extract text from Word Documents contained in a directory in the project folder. For the purpose for the example we’ll simply create a directory called documents and populate it with some word documents.
In order to extract the contents of the documents, we’ll make use of a popular Python library textract .
In order to use textract we will first need to install it to our environment. So can open the integrated terminal window ( alt + f12) and install our package using Conda
Conda will install your package, it will also ask you to confirm your choice.
Lets create a simple Python file in our project and name it extract.py . To do right click project folder in the project view and select New -> Python File
We can now write the code we need to create our simple example
Run and Debug your Project
We can now run and debug our project, in order to do so we will need to create configuration.
Open the Run/Debug Configurations using Run -> Edit Configurations
Anaconda Pycharm Windows
Click the + in the right hand corner then select Python then select the Script path: the path where your extract.py
We can now set a break point in our code and if we run start a debug session our code will stop on break point and we can step through as required.
It’s super easy to use Pycharm and Conda together to create Python projects and use Conda to manage our project dependencies.
Pycharm Anaconda Community Edition
- The Adapter Pattern - May 4, 2021
- Implement log monitoring with Seq and Serilog in .net Core - May 2, 2021
- Book Review: Head First Design Patterns - April 29, 2021