Missmatched remote pip path and enviroment
I'm currently experiencing an issue with PyCharm, where when using a remote interpreter from a (remote) virtual environment, the PATH variable is set wrong. This leads to the wrong pip executable being used by PyCharm to install packages through the Python Packages feature as well as Intellisense thinking packages are not installed.
My Setup:
- PyCharm 2023.3.2 (Professional Edition)
- Remote Interpreter: `Remote Python 3.11.6 (stp://user@host:22/home/user/.virtualenvs/my_project/bin/python)`
- I set up the remote interpreter through “add new Interpreter” → “on SSH…” and did no other configuration.
When executing !pip --version in the Python console /home/user/.virtualenvs/my_project/bin/python /home/user/.pycharm_helpers/pydev/pydevconsole.py --mode=client --host=localhost --port=44029 the output is pip 23.1.2 from /usr/local/lib/python3.10/dist-packages/pip (python 3.10), which is the remote local pip installation. Instead one would expect pip from the virtual environment.
Did I configure anything wrong? Or is there a way to manually set the PATH variable?
Here is some more information, and one can clearly see that the PATH variable is set wrong, it seems, though, that the sys.path variable inside of Python is set right.
import sys
import os
import pkg_resourcesPython
from pprint import pprint
pprint({
'sys.version_info': sys.version_info,
'sys.prefix': sys.prefix,
'sys.path': sys.path,
'pkg_resources.working_set': list(pkg_resources.working_set),
'PATH': os.environ['PATH'].split(os.pathsep),
}){'PATH': ['/home/user/.cargo/bin',
'/usr/local/sbin',
'/usr/local/bin',
'/usr/sbin',
'/usr/bin',
'/sbin',
'/bin',
'/usr/games',
'/usr/local/games',
'/snap/bin'],
'pkg_resources.working_set': [Babel 2.14.0 (/home/user/.virtualenvs/my_project/lib/python3.11/site-packages),
...
yarl 1.9.4 (/home/user/.virtualenvs/my_project/lib/python3.11/site-packages)],
'sys.path': ['/home/user/.pycharm_helpers/pydev',
'/home/user/.pycharm_helpers/third_party/thriftpy',
'/home/user/.pycharm_helpers/pydev',
'/tmp/pycharm_project_376',
'/home/user/.pycharm_helpers/pycharm_display',
'/usr/lib/python311.zip',
'/usr/lib/python3.11',
'/usr/lib/python3.11/lib-dynload',
'/home/user/.virtualenvs/my_project/lib/python3.11/site-packages',
'/home/user/.pycharm_helpers/pycharm_matplotlib_backend',
'/tmp/pycharm_project_376/'],
'sys.prefix': '/home/user/.virtualenvs/my_project',
'sys.version_info': sys.version_info(major=3, minor=11, micro=6, releaselevel='final', serial=0)}
请先登录再写评论。
Partially, this is a known issue with activating virtual environments on the remote hosts: the PATH variable is not updated, but PYTHONPATH should be just fine, and it should run the script with the proper environment.
I've additionally checked if installing packages from the PyCharm package manager works as expected, and it installs packages to a proper remote venv.
Could you please clarify if the virtual environment was created on a target host and hasn't been moved since creation? If it was created somewhere else - let us know. Also, please run the !pip --version command and post a screenshot of the tool window with the output here.