How to switch between local and installed version of python package, including IDE support (PyCharm)?
Asked Answered
N

1

0

I develop a package fhg_isi and currently have installed version 0.0.1.

What is the recommended way to switch between the local version 0.0.2 (being in development) and the installed version?

I am already able to load the local version by modifying the system path (and If I want to use the installed version, I can comment out the modification of the system path)

import sys

# If you want to use the local version of fhg_isi package,
# insert its absolute path to the python system path, for example:
local_fhg_isi_path = 'C:/python_env/workspace/fhg_isi/src'
sys.path.insert(1, local_fhg_isi_path)  # out comment this line to use installed version

from fhg_isi.gis.geojson_factory import GeojsonFactory  # This import stays the same for both cases
...

Also see: How can you import a local version of a python package?

However, PyCharm does not recognize the switch of the libraries. If I Ctrl-Click on GeojsonFactory, I still navigate to the installed version instead of local version.

=> Is there a more comfortable way to switch between the packages, including IDE support, without modification of all the import statements?

Nickelson answered 1/9, 2023 at 8:30 Comment(1)
Hello Stefan, Why just not using two different virtual environments? You activate one or the other, depending the version you want (same dir, same code, same project). Some developer uses environment variables (and API directories on src): on ISI you have `if ..: from v2.ISI import *, etc.)Providential
N
0

The behavior of PyCharm can be influenced with the Projekt Structure settings and the run configuration option Add source roots to PYTHONPATH.

Once I configured the "src" folder as Source folder (=> blue color), the navigation worked as expected.

enter image description here

An alternative approach might also be to use virtual environments and switch between them, as Giacomo suggested in the comment.

Nickelson answered 1/9, 2023 at 9:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.