48

I'm doing a fresh install on a new Windows 10 laptop. I installed Python 3.9 and PyCharm Community 2020.2, then started a new project. In the project settings, I created a new project interpreter in a venv, inside the /venv folder. Everything looks to get set up correctly, but I can't install anything to the project interpreter. When I try to do so, e.g. when I try to install pandas or anything else, I get None-zero exit code (2) with the following message:

Usage: D:\MyProject\project\venv\Scripts\python.exe -m pip install [options] [package-index-options] ...
D:\MyProject\project\venv\Scripts\python.exe -m pip install [options] -r [package-index-options] ...
D:\MyProject\project\venv\Scripts\python.exe -m pip install [options] [-e] ...
D:\MyProject\project\venv\Scripts\python.exe -m pip install [options] [-e] ...
D:\MyProject\project\venv\Scripts\python.exe -m pip install [options] <archive url/path> ...

no such option: --build-dir

When I go to the Terminal and just 'pip install pandas' per PyCharm's 'proposed solution', it installs fine, and pandas and its dependencies appear as usual in the list of installed modules in the interpreter. I've not encountered this before, and don't see anywhere in the settings where I can specify how exactly PyCharm will invoke pip in this situation.

Helenus the Seer
  • 717
  • 1
  • 7
  • 10

3 Answers3

60

PyCharm relies on --build-dir to install packages and the flag was removed in the latest pip 20.3.

The fix for PyCharm is ready and will be released this week in 2020.3 release (and backported to 2020.2.5 and 2020.1.5).

The workaround is to downgrade pip to the previous version - close PyCharm and run python -m pip install pip==20.2.4 in the terminal using the corresponding virtual environment.

Update 1

2020.1.5 and 2020.2.5 with the fix were released - please update.

Pavel Karateev
  • 7,737
  • 3
  • 32
  • 59
  • Pavel, thanks for the quick response. When I tried your workaround with Admin access, however, I got this: 'ERROR: Could not install packages due to an EnvironmentError: [WinError 5] Access is denied: 'd:\\myproject\\project\\venv\\scripts\\pip.exe'. And it broke the existing pip. The interpreter now shows no pip module, but instead an '-ip' module. Pip is no longer working in the Terminal. Any suggestions? – Helenus the Seer Dec 01 '20 at 09:13
  • 2
    Ah, this pesky Windows, try closing PyCharm, and run `python -m pip install pip==20.2.4` (make sure the correct venv is activated). – Pavel Karateev Dec 01 '20 at 09:21
  • 1
    OK, confirmed that this worked, and allows me to use the UI to add/remove packages from the venv. Sorry I didn't recognize that the permission error was from PyCharm itself. Thanks again! – Helenus the Seer Dec 01 '20 at 09:44
  • I see that this workaround works well in general cases. In my case, I'm about to do 'TensorFlow Developer Certificate Exam' via 'TensorFlow Developer Certificate exam' plugin, which will create a new venv and starts installing the required packages. And due this error in installing packages, I canceled the exam. Would like to know where can I find the exact date for this update or if there is a workaround for my case too? – hareen tej Dec 02 '20 at 05:35
  • 1
    @hareentej The fixed versions are released. – Pavel Karateev Dec 02 '20 at 08:15
  • 1
    PyCharm 2020.2.5 is there. I just updated it and can confirm that it works again. – Matthias Dec 02 '20 at 08:15
  • @PavelKarateev That's stead fast and working like a charm. Thank you for what you guys doing for the community. – hareen tej Dec 03 '20 at 13:11
2

Pycharm 2020.3 released and it seems like the issue solved by upgrading to this version.

Adimz
  • 41
  • 1
  • 3
0

I use the code as fellow at the terminal in PyCharm: venv\Scripts\python -m pip install pip==20.2.4

attention:you must key in this code in the terminal at PyCharm otherwise you can't change the version for your project.

tip:When it done,you can find the version of pip is right at settings-project interpreter.

YZQ
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 11 '23 at 06:05