How to set up Python Development Project with PyCharm

Wasin Waeosri
LSEG Developer Community
10 min readJun 12, 2023

--

Introduction

The original article on the Refinitiv Developer Community is available here.

PyCharm is a flagship cross-platform Python IDE developed by JetBrains (the same company that developed IntelliJ IDEA for Java/Kotlin). The IDE provides coding assistance such as code completion and syntax/error highlight, project and code navigation, package management, debugger, version control, and much more.

PyCharm has two editions, a Professional Edition with full features, and a free Community Edition (see the comparison), this makes the IDE attractive to both newbie and full-stack Python developers.

As a developer, I am using the IntelliJ IDEA for Java development projects and Visual Studio Code editor for Python and JavaScript/TypeScript development projects. I admit that I am never interested in PyCharm. However, there are a lot of questions about how to use our Python APIs/libraries with PyCharm, so it is a good opportunity for me to learn how to use PyCharm and share my knowledge.

This example project shows how to create a Python project with the Refinitiv Data Library for Python on PyCharm. It covers from starting a blank project to importing existing source code and dependencies configuration file to the IDE.

Note: This project is based on PyCharm Community Edition 2023.1.2 and the Classic UI. If you are using a Professional Edition or New UI, some user interfaces may be different.

Python and PyCharm prerequisite

Before I am going further, there is some prerequisite, dependencies, and libraries that the project is needed.

PyCharm

Firstly, you can download (or purchase) the PyCharm IDE installer file from PyCharm website.

Anaconda or Miniconda

Next, install the Anaconda or Minconda in your machine.

This project uses Miniconda version 23.3.1.

Access to the Refinitiv Data Platform

This project uses Refinitiv Data Platform (RDP) User ID type credential (example: sample@lseg.com).

Please contact your Refinitiv representative to help you with the RDP account and services.

Internet Access to PyPI

The Refinitiv Data Library for Python is available in the Python Package Index (PyPI). You can use the Python pip tool to download the library from Refinitiv-Data package over internet.

What is Refinitiv Data Library for Python?

Now let me turn to our example Python library for this project. The Refinitiv Data Library for Python (aka RD Lib — Python) provides a set of ease-of-use interfaces offering coders uniform access to the breadth and depth of financial data and services available on the Refinitiv Data Platform. The API is designed to provide consistent access through multiple access channels and target both Professional Developers and Financial Coders. Developers can choose to access content from the desktop, through their deployed streaming services, or directly to the cloud. With the Refinitiv Data Library, the same Python code can be used to retrieve data regardless of which access point you choose to connect to the platform.

This example project is focusing on the platform session which connecting to the Refinitiv Data Platform APIs only.

Refinitiv Data Library

For more detail regarding the Refinitiv Data Platform, please see the following APIs resources:

That covers a brief introduction to Refinitiv Data Library for Python.

Set up a blank project

Step 1: Creating a new project

Firstly, create a new development project. Please open the PyCharm IDE and choose “New Project” on the welcome screen.

step 1: new project

Next, input the project location (I pick C:\drive_d\Project\Code\Pycharm_RD_Python folder as my work location) and set the following properties:

  • New environment using: Conda
  • Location: Point to your <Conda>\envs\<Project name>
  • Python version: Based on your preference, I choose Python 3.10. Please refer to the Python End Of Life page
  • Conda executable: Point to <Conda>\Script\conda.exe location in your Conda installation folder
  • Create a main.py welcome script: Choose this option
PyCharm new project

Note: PyCharm supports the Virtualenv, Pipenv, Poetry, and Anaconda/Minconda Python virtual environment and Packaging/Dependencies Management tools. I choose Conda for Python versioning flexibility. Please choose this option based on your development requirement.

Then PyCharm initializes the project and Conda environment. Once the project and Conda environment are created successfully, you see this IDE screen with an example main.py code as follows:

create new project success

You can use this example main.py script to test if PyCharm can run Python properly on your machine. To run the code, right-click and choose Run 'Main' menu or click the Run command at the toolbar.

Run Python project

The result is as follows:

Now the basic Python setting is done for PyCharm.

Step 2: Set up the Project setting for Refinitiv Data Library for Python

So, now let’s look at installing the Refinitiv Data Library for Python dependencies. Firstly, open the Python Package tool window available at the bottom of the screen as follows:

PyCharm Package tool window

You can start typing the package name in the Search field. PyCharm then shows matching packages on each repository. Since we are using a Conda environment, so PyCharm shows search results on both Conda and PyPI repositories like the following search result for the python-dotenv package.

To install Refinitiv Data Library for Python, type refinitiv in the Search field. The RD Lib — Python is available on PyPI only, so I choose the refinitiv-data package under PyPI and click the “Install with pip” button to install the package.

PyCharm install refinitiv-data 1

Once the package installation is successful, you see the notification, and the refinitiv-data package is listed in the installed packages.

PyCharm install refinitiv-data 2

The next step is testing the RD Lib — Python. You can add the refinitiv-data.config.json file to the IDE with the following configurations:

Please refer to the Quickstart page if you are using other Access Points such as Desktop session, etc.

Next, change the code of main.py to call RD - Lib Python instead as follows:

Your PyCharm IDE should look like the following screenshot:

PyCharm with RD Code

If your RDP credential works fine, the running result shows as follows:

PyCharm with RD Run Result

Now your PyCharm is ready to work with Refinitiv Data Library for Python. Let’s leave a main.py file there.

For more detail about packages management with PyCharm, please check the official document.

Step 3: Plotting Graph

Now we come to how to plot a graph with PyCharm. Please note that the Jupyter Notebook integration is available in PyCharm Professional Edition only, so I am demonstrating with a basic graph from a console application instead.

The first step is to install the Matplotlib library. You can open the Python Package tool window to install the package. However, the PyCharm has Terminal emulator that run the project Conda (or Virtualenv) shell automatically and you can run the pip and conda commands to manage the Python environment directly.

To open the Terminal, just click the Terminal tool window at the bottom of the screen. You see that it activates Conda Pycharm_RDPython by default.

The Matplotlib library is available on both conda-forge and PyPI, let’s stick with the PyPI for consistency and install the package with the pip install command.

(Pycharm_RD_Python) C:> pip install matplotlib
installing Matplotlib

Next, add a new Python file chart.py to the IDE with the following source code.

Please see how to add Python files from the official page.

The result is as follows:

Graph result

That’s all I have to say about plotting graphs in PyCharm IDE.

Step 4: Save and Export Dependencies

My next point is how to save and export this project’s dependencies. It is one of the most important parts to help share the project with your colleagues. With the right setting, your team (or even yourself) can re-create this development environment in simple steps.

A requirements.txt is a simple text file that saves a list of the Python modules and libraries required by the project/Python environment. To generate a file, you can open the Terminal tool window and run the following command:

Pycharm_RD_Python) C:> pip freeze  > requirements.txt
pip freeze

That covers how to save and export this project’s dependencies.

Import existing code to PyCharm

If you have existing Python source code, requirements.txt, and other configuration files. You can create a new PyCharm project with existing files to continue developing the application using PyCharm.

Step 1: Create a new project with a non-empty folder

I pick the C:\drive_d\Project\Code\Pycharm_RD_Python_2 folder as my new work location. The folder contains some Python and RDP configuration files as follows:

Next, I am creating a new project on that folder with the same option as a blank project, except uncheck the “Create a main.py welcome script” option as follows:

new project on existing code

PyCharm IDE can detect that the target folder is not empty and asks if we want to create a new project from existing sources, choose this option.

new project on existing code

Once the project and Conda environment are created successfully, you see this IDE screen with existing code as follows:

You may be noticed that the IDE can detect the source code use the Python libraries that not installed in the Conda environment yet. If you open a requirements.txt file, the IDE shows the same message as well.

install dependencies

I am not recommended you install the required libraries with the IDE tool’s “install requirements” button. Based on my experience, I always encounters pip install error issue.

To install required library, I highly recommend you open the Terminal window and install dependencies to the active environment with the following command instead.

(Pycharm_RD_Python_2) PS C:> pip install -r .\requirements.txt
install dependencies

Now this project is ready for RD Library — Python coding.

Reuse existing Conda environment

One benefit of using Anaconda/Miniconda over Virtualenv is developers can share a Conda environment with multiple projects. If the projects share the same dependencies requirements, developers do not need to create a new Conda environment.

For example, I am creating a new Pycharm_RD_Python_3 project at C:\drive_d\Project\Code\Pycharm_RD_Python_3 folder but I want to use Pycharm_RD_Python Conda environment with this project.

In the new project window, choose the “Previously configured interpreter” option, and click the “Add Local Interpreter..” menu.

Use existing Conda environment

In the Add Python Interpreter window, choose “Conda Environment” and select the environment that you want to use from a drop-down list as follows:

Use existing Conda environment

You may want to change Python interpreter/environment on the fly to test the project with other versions of Python or libraries. You can change the project’s interpreter/environment by clicking on the Python Interpreter selector located on the status bar.

Change Python Interpreter on the fly

That is all for how to reuse or change the Python environment on the fly.

Please see more detail on the Configure a Python interpreter page.

Troubleshooting

Error: “Environment location directory is not empty” when creating a new project.

Environment location directory is not empty error

Answer: This error message means you are creating a duplicate Conda environment which is not allowed by the IDE and Conda. You must remove an environment and remove <Conda>\envs\<env name> folder in your machine manually.

Error: I cannot run Jupyter notebook or .ipynb file in PyCharm Community Edition.

Answer: The Jupyter Notebook integration supported is available in PyCharm Professional Edition only.

Error: Can I use Eikon Data API in PyCharm?

Answer: Yes, you can. You just install Eikon Data API library to the environment.

Error: I want to use Spyder IDE. How can I use it?

Answer: Please check the Spyder IDE official page and document for more detail.

Error: Where can I find more detail about PyCharm usage?

Answer: Please check the PyCharm Getting started page for more detail.

Conclusion

PyCharm is one of the most popular IDEs for Python development. It supports Python virtual environment, Package management, and deployment, plugins supported, etc. Python developers can gain benefits from IDE automation and a full-features development environment. These make PyCharm suitable for the rapid development nature of Refinitiv Data Library for Python.

I hope this step-by-step guide can help Python developers get started using our Python libraries with PyCharm IDE. That completes my article.

References

For further details, please check out the following resources:

For any questions related to this article or the Refinitiv Data Library for Python, please use the Developer Community Q&A Forum.

--

--