简体   繁体   中英

import package from my Pycharm project and not from my conda environment

I am working on a python project in Pycharm. Lately I have created a setup.py in order for collaborators to be able to install and test the project on their systems. To test that everything is working fine, I have also installed it in my conda environment, which is the same as used by the interpreter in my Pycharm project. Now when I import my package in Pycharm it gets imported from the conda environment and not from my Pycharm project. Is there a way to tell Pycharm to look first in the Pycharm project subdirectories and then in the conda environment? Or do I need to uninstall my package from the conda environment that I use in Pycharm?

The proper way to go is to first create a virtual environment and then install your package in editable mode along with its required dependencies, as specified in setup.cfg .


Step 1: Activate your virtual environment

source /path/to/your/venv/bin/activate

or

conda activate vevnName

Step 2: Install your package in editable mode

pip3 install -e .

This command is going to install your package and link it to the original location (ie the one that probably you want to be editing in PyCharm) so that any change being made is also replicated on your venv.


You can now open your Python application on PyCharm, from its original location and any changes you make in your IDE will be reflected directly on your virtual environment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM