6
votes

I have a Python project that has a requirements.txt project for pip install to use. I have opened that project in PyCharm. (Side note: PyCharm uses many of the same engines as IntelliJ when it comes to Git integration, so I've tagged that, too).

Upon opening a Python file, as expected PyCharm tells me, "Package requirements are not satisfied." I click "Install Requirements" and after a short time get some errors. All of the errors are related to private GitHub repositories (in requirements.txt as "git+ssh://[email protected]..."). All of the errors are the same:

Please make sure you have the correct access rights
and the repository exists.

I can run pip install from the command line without issue, so the problem is not with requirements.txt. The problem appears to be PyCharm not using my GitHub SSH keys (it has never asked me for my SSH key password). The PyCharm docs say to make sure that your public and private keys exist in $HOME/.ssh/id_rsa.pub and $HOME/.ssh/id_rsa, respectively, and they do. I have also set up GitHub settings so that PyCharm knows my username and password, but that also did not work.

None of the public Git/GitHub repositories in requirements.txt cause any problems (they all installed fine). It's only these two private GitHub repositories that PyCharm can't seem to install requirements from.

How do I get PyCharm to use my GitHub SSH keys when installing requirements from requirements.txt?

2
I followed this answer from a similar question to get it working: stackoverflow.com/a/46141944/3041389.BjornArnelid

2 Answers

1
votes

One workaround is to open PyCharm (or Intelli-J) from the console, instead of via the Application icon, or the project.

Make sure you have created a command line launcher from the tools menu, then use the newly available charm command to open your project. It's possible to also just run open /Applications/PyCharm.app, but I believe charm also allows you to specify the project to open.

Instances of PyCharm launched in this way will have inherited your terminal environment. I will admit I haven't tested private Git repositories in requirements.txt with this, but it has solved other issues related to the environment, so I'd give it a try.

0
votes

That's normal because PyCharm is a GUI OS X application which means that it does not share the same environment as your terminal apps.

I had lots and lots of problems due to this, not only with PyCharm.

Due to this problem the ssh agent is not able to share its environment so your key is not loading.

Workaround: remove password from your key, or use HTTP(s) inside requirements.txt --- anyway is quite weird to see SSH inside these, but who knows what kind of security measures you are forced to use in your case.