237

Searching the net this seems to be a problem caused by spaces in the Python installation path.

How do I get pip to work without having to reinstall everything in a path without spaces ?

Csaba Toth
  • 10,021
  • 5
  • 75
  • 121
Arc
  • 11,143
  • 4
  • 52
  • 75
  • 1
    Have you tried using short path names for program files(X86)? e.g. "C:\PROGRA~2\Python33\python.exe" – Shadow9043 Jul 08 '14 at 08:55
  • 4
    The problem is that when `pip` is installed, it will use the original, long name it gets from the system. See my answer below. – Arc Jul 09 '14 at 09:57
  • 2
    Reproducable with Python 2.7 and Windows 10 Preview build 10074 – Csaba Toth May 07 '15 at 23:32
  • 2
    @CsabaToth, I have to correct your edit: The double quotes were correct as they were before your change; they were just omitting the single quotes: The verbatim error is: `Fatal error in launcher: Unable to create process using '""C:\Program Files (x86)\Python33\python.exe"" "C:\Program Files (x86)\Python33\Scripts\pip.exe" '`. Looks strange, but it's the way it is. – Arc May 25 '15 at 05:35
  • I was using Powershell (Admin) and it works on first go. – Aakash Choubey Dec 21 '17 at 14:56
  • pip sucks. python sucks. django sucks. – Alston Dec 25 '22 at 14:25

30 Answers30

485

it seems that

python -m pip install XXX 

will work anyway (worked for me) (see link by user474491)

Community
  • 1
  • 1
user4154243
  • 4,914
  • 1
  • 11
  • 2
  • 9
    Made it the accepted answer, though it's more of a workaround (or alternative approach) than an actual fix, but anyways, it is more universally applicable. – Arc Jan 16 '15 at 14:31
  • 2
    @user4154243, that works, but can you explain what it actually does? Are there consequences using that to install every other library? – multigoodverse Sep 22 '15 at 08:34
  • 1
    you save me, I was trying to configure oddo and its need to configure python. I was try 5 6 hrs for the same issue, finally its work from your idea. big thanks. I also add my answer for oddo related work. – Ajay2707 Nov 27 '15 at 06:41
  • 1
    Had this issue in a virtualenv, used your solution to install the latest pip, which then allowed use of the command normally: python -mpip install pip --upgrade – tr00st Dec 01 '15 at 15:59
  • Worked for me. The important part is `python -m pip` then the rest can be any pip command, such as `python -m pip freeze`, which is the one that I was trying to run in PowerShell and Command line. – edmundo096 Dec 08 '15 at 21:01
  • I get this error now `Error while finding spec for 'pip.__main__'` –  Apr 26 '16 at 02:46
  • 5
    this is a workaround and should not be the accepted answer – Raiden Core Jun 28 '16 at 16:40
  • This worked for me. When I ran it, however, I received an error message `error: could not create 'C:\Program Files (x86)\Python34\Lib\site-packages\tinys3': Access is denied`. Opening a CMD window as administrator and re-running `python -m pip install ` worked flawlessly. – Moshe Rubin Oct 02 '16 at 09:35
  • @user4154243 My system gets BSOD after running this command. Has anyone faced this issue ? – YetAnotherBot Nov 01 '17 at 10:00
  • 1
    `Could not find a version that satisfies the requirement XXX (from versions: )No matching distribution found for XXX` – Schütze Dec 21 '17 at 11:22
  • 1
    Try the following: python -m pip install --upgrade pip – Taras Melnyk May 08 '18 at 20:18
  • 1
    Installing using 'python -m pip install xxx' doesn't work for me. Windows 10, trying to install 'memory-profiler'. I'm using latest pip. Can't downvote yet. – majTheHero Jul 10 '18 at 13:32
82

On Windows at least, pip stores the execution path in the executable pip.exe when it is installed.

Edit this file using a hex editor or WordPad (you have to save it as plain text then to retain binary data), change the path to Python with quotes and spaces like this:

#!"C:\Program Files (x86)\Python33\python.exe"

to an escaped path without spaces and quotes and pad with spaces (dots at the end should be spaces):

#!C:\Progra~2\Python33\python.exe.............

For "C:\Program Files", this path would probably be "C:\Progra~1" (shortened path names in DOS / Windows 3.x notation use tilde and numbers). Windows provides this alternative notation for backwards compatibility with DOS / Windows 3.x apps.

Note that as this is a binary file, you should not change the file size which may break the executable, hence the padding.

Save with administrator privileges, make sure it is actually saved at the target location and try again.

You might also need to set the PATH variable to use the ~ notation for the path to pip.

Arc
  • 11,143
  • 4
  • 52
  • 75
  • An exe file is binary. How can I spot the exact place where this path is writtne? – Sohaib Jul 31 '14 at 09:46
  • What do you mean, where "this path is written" ? `PATH` is an environment variable that you can set in via Control Panel, System like this: http://www.faqforge.com/windows/setting-the-path-environmental-variable-on-windows-7/ (Windows 8 key Windows+X, System). Has nothing to do with the EXE. If you want to know where the EXE is coming from, well, there are utility programs like `which` under UNIX/Linux, or you can search through your `PATH` directories. – Arc Jul 31 '14 at 11:06
  • 1
    I did not mean the environment variable. I only meant where this string appeared `"#!"C:\Program Files (x86)\Python33\python.exe"` I was able to find out where it was though using a hex editor. However using Sublime Text no such string was visible. Can you think of any reason why the path is shown in Wordpad and not in Sublime Text? – Sohaib Jul 31 '14 at 11:22
  • 2
    WordPad is a dumb text editor, Sublime is probably too smart and shows a hex dump of the contents, I guess. – Arc Jul 31 '14 at 13:09
  • 6
    This worked for me. My original string was `#!"C:\Program Files\Python3.4\python.exe"`, so I changed it to `#!C:\Progra~1\Python3.4\python.exe ` and it worked. I was able to edit the file fine with Notepad++. This string shows up near the end of the file, at the end of a long line. – Scott Weldon Jul 31 '14 at 20:04
  • 1
    Good and functional workaround. But it is important to note that the dots after the path are NULL chars (00 in hex) and that the size of the file should *not* be changed. – Diego Queiroz Oct 16 '14 at 00:55
  • 3
    This worked. I simply uninstalled python. Then reinstalled; upon reinstall, I just changed the install folder from `C:\Program Files (x86)\Python34` to be `C:\Progra~2\Python34`. (if you do not wish to deal with a hex editor or changing a binary file) – Trent Jan 09 '15 at 06:06
  • Excelent solution. I made it work portably (for a personal project) using `#!..\python.exe`. The same solution worked for easy_install too. – jheyse Feb 10 '15 at 14:28
  • Do you mind editing "WordPad (you have to save it as plain text then to retain binary data)," so that it is correct and clear. I think WordPad should be replaced by NotePad but i'm not exactly sure how to correct the rest of the wording/punctuation. (BTW, successfully implemented your solution.) – Martin F Mar 11 '15 at 22:05
  • @martinf To my knowledge, Notepad is "less binary-safe" than WordPad and may corrupt your file. Therefore WordPad with plain text save option. But best is of course a binary data / hex editor. I just tried to edit a binary with both, inserting a char, saving, quitting, reopening, removing that char and saving again. WordPad's output was exactly the same as the original input. Notepad killed that binary. – Arc Mar 19 '15 at 22:50
  • 6
    "On Windows at least, pip stores the execution path in the executable pip.exe when it is installed." Now THAT is stupid -.- Did cost me half an hour to figure that out. – plocks Apr 13 '15 at 13:11
  • I was able to rename the offending folder in the path to not contain a space, and recreated the virtualenv which contained pip. Then I ran pip again and this error went away. If this is an option for you, then no hex editor is required. – ckb Oct 13 '15 at 21:33
  • This worked for me. My problem was I changed the driver letter from E: to F: where Python was installed, then anything under Python34\Scripts stopped working. – techolic Apr 04 '16 at 02:21
  • Thanks! Fixed with `notepad++` + `HEXEditor plugin`. This is was not a good idea to rename folder with virtual env. – Ivan Borshchov Sep 12 '16 at 14:25
  • Wow, path hardcoded in the EXE? I would never have guessed, but THANKS for clearing that up. My solution was to install Python clean to a VM duplicating the path I wanted, then copy pip.exe out from there. Note that easy_install.exe and all the EXEs in the Scripts folder are affected. – GravityWell Nov 17 '17 at 18:13
  • I had renamed my Python executable to python3.exe. This breaks the pip. – douggard Jan 05 '18 at 05:36
  • I just opened pip.exe using Notepad++, removed the quotes around the path and saved. Pip works now. I didn't even have to use the short path with tildes. And I didn't need a hex editor. – user31389 Apr 19 '18 at 12:00
  • This happened to me because I moved a virtualenv directory and shouldn't do that. In my case it was to a subdirectory so the path was longer, but I didn't remove any padding (from where?) and pip now works. The rest of the virtualenv scripts need fixing too though. Best not to move virtualenvs, or use --relocatable swtich – Davos May 09 '18 at 10:15
  • I'm going to suggest that this works, however, the problem can be resolved by re-installing "for all users" instead of selecting the default install into the user's appdata dir. – truedat101 Nov 18 '18 at 06:49
  • Thanks, this solved my issue, as of python 3.9.7, pip is still f***ed up and brings a hardcoded python 3.8 path in it. – Ezequiel Barbosa Sep 06 '21 at 17:31
39

having the same trouble I read in https://pip.pypa.io/en/latest/installing.html#install-pip that to update pip it's:

python -m pip install -U pip

So I made (for example)

python -m pip install virtualenv

And it worked! So you can do the same being 'virtualenv' another package you want.

MiguelCldn
  • 527
  • 5
  • 3
  • 4
    I was suffering from the error listed and this was the solution that worked for me! I was even able to use 'pip install virtualenv' and stop using 'python -m pip' after making the upgrade to latest pip. Thanks! – steve-gregory Jan 30 '15 at 06:21
20

python -m pip

really works for the problem Fatal error in launcher: Unable to create process using '"'.Worked on Windows 10

Xantium
  • 11,201
  • 10
  • 62
  • 89
Joel K Thomas
  • 225
  • 2
  • 2
19

I had a similar issue and upgrading pip fixed it for me.

python -m pip install --upgrade pip 

This was on Windows and the path to python inside pip.exe was incorrect. See Archimedix answer for more information about the path.

Community
  • 1
  • 1
Johan Gov
  • 1,262
  • 1
  • 13
  • 26
6

Here's how I solved it:

  1. open pip.exe in 7zip and extract __main__.py to Python\Scripts folder.

    In my case it was C:\Program Files (x86)\Python27\Scripts

  2. Rename __main__.py to pip.py

  3. Run it! python pip.py install something

EDIT:

If you want to be able to do pip install something from anywhere, do this too:

  1. rename pip.py to pip2.py (to avoid import pip errors)

  2. make C:\Program Files (x86)\Python27\pip.bat with the following contents:

python "C:\Program Files (x86)\Python27\Scripts\pip2.py" %1 %2 %3 %4 %5 %6 %7 %8 %9

  1. add C:\Program Files (x86)\Python27 to your PATH (if is not already)

  2. Run it! pip install something

apple16
  • 1,137
  • 10
  • 13
5

This is a known Bug when there is a space in the virtualenv path. Correction has been made, and will be available in the next version.

StuartLC
  • 104,537
  • 17
  • 209
  • 285
Pierre Carbonnelle
  • 2,305
  • 19
  • 25
4

i had same issue and did a pip upgrade using following and now it works fine. python -m pip install --upgrade pip

Dev
  • 316
  • 1
  • 4
  • 15
2

I renamed the executable of python.exe to e.g. python27.exe. In respect to the answer of Archimedix I opened my pip.exe with a Hex-Editor, scrolled to the end of the file and changed the python.exe in the path to python27.exe. While editing make shure you don't override other informations.

Community
  • 1
  • 1
Markus Weber
  • 1,059
  • 1
  • 11
  • 24
2

I wrote a script to patch those exe. But the best way is to fix distutil itself.

"""Fix "Fatal error in launcher: Unable to create process using ..." error. Put me besides those EXE made by pip. (They are made by distutils, and used by pip)"""
import re
import sys
import os
from glob import glob


script_path = os.path.dirname(os.path.realpath(__file__))
real_int_path = sys.executable
_t = script_path.rpartition(os.sep)[0] + os.sep + 'python.exe'
if script_path.lower().endswith('scripts') and os.path.isfile(_t):
    real_int_path = _t

print('real interpreter path: ' + real_int_path)
print()

for i in glob('*.exe'):
    with open(i, 'rb+') as f:
        img = f.read()
        match = re.search(rb'#![a-zA-Z]:\\.+\.exe', img)
        if not match:
            print("can't fix file: " + i)
            continue
        int_path = match.group()[2:].decode()
        int_path_start = match.start() + 2
        int_path_end = match.end()

        if int_path.lower() == real_int_path.lower():
            continue
        print('fix interpreter path: %s in %s' % (int_path, i))
        f.seek(int_path_start)
        f.write(real_int_path.encode())
        f.write(img[int_path_end:])
krrr
  • 579
  • 6
  • 14
  • 1
    I had the error "Unable to create process" when I tried to run eb.exe (part of AWS Elastic Beanstalk CLI) and this little script fixed eb.exe! It works now, thanks. – JustAC0der Dec 08 '17 at 08:25
  • This worked for me but only after changing the code to match the length from the real_int_path with the int_path. I padded it with spaces as suggested by the answer from Archimedix. – lou Jun 05 '18 at 10:51
2

I had the same issue on windows 10, after trying all the previous solution the problem persists so I decided to uninstall my python 2.7 and install the version 2.7.13 and it works perfectly.

Badr Bellaj
  • 11,560
  • 2
  • 43
  • 44
2

This can happen if you are using a case-sensitive file system on Windows. You can tell if this is the case if there is both a lib directory and a Lib directory in your venv directory :

> dir

Directory: C:\git\case\sensitive\filesystem\here\venv

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        4/07/2018   4:10 PM                Include
d-----       22/01/2019   7:52 AM                Lib
d-----       22/01/2019   7:52 AM                lib
d-----       22/01/2019   7:52 AM                Scripts
d-----       22/01/2019   7:52 AM                tcl

To workaround this (until virtualenv.py gets fixed: https://github.com/pypa/virtualenv/issues/935) merge the two lib directories and make venv case-insensitive:

cd venv
move Lib rmthis
move .\rmthis\site-packages\ lib
rmdir rmthis
fsutil.exe file setCaseSensitiveInfo . disable
cdjc
  • 1,039
  • 12
  • 24
  • I did not have a 'Lib' and 'lib' directory, but still ran into this issue. You can use the following to directly determine if the venv directory is case-sensitive `fsutil.exe file queryCaseSensitiveInfo .venv`. Additional background about case-sensitive file-systems in Windows can be found at https://devblogs.microsoft.com/commandline/per-directory-case-sensitivity-and-wsl/ – CodeButcher May 05 '20 at 18:46
2

Here is how i fixed it.

  1. Download https://bootstrap.pypa.io/get-pip.py
  2. Active your vitualenv
  3. Navigate to the get-pip.py file and type "python get-pip.py" without quote.

it will reinstall your pip within the environment and uninstall the previous version automatically.

now boom!! install whatever you like

1

Please add this address :

C:\Program Files (x86)\Python33

in Windows PATH Variable

Though first make sure this is the folder where Python exe file resides, then only add this path to the PATH variable.

To append addresses in PATH variable, Please go to

Control Panel -> Systems -> Advanced System Settings -> Environment Variables -> System Variables -> Path -> Edit ->

Then append the above mentioned path & click Save

Shaminder Singh
  • 1,283
  • 2
  • 18
  • 31
1

I added my anwer because I have getting the same error while configure ODDO9 source code in local and its need the exe to run while run exe, I got the same error.

From yesterday I was configure oddo 9.0 (section :- "Python dependencies listed in the requirements.txt file.") and its need to run PIP exe as

C:\YourOdooPath> C:\Python27\Scripts\pip.exe install -r requirements.txt

My oddo path is :- D:\Program Files (x86)\Odoo 9.0-20151014 My pip location is :- D:\Program Files (x86)\Python27\Scripts\pip.exe

So I open command prompt and go to above oddo path and try to run pip exe with these combination, but not given always above error.

  1. D:\Program Files (x86)\Python27\Scripts\pip.exe install -r requirements.txt
  2. "D:\Program Files (x86)\Python27\Scripts\pip.exe install -r requirements.txt" Python27\Scripts\pip.exe install -r requirements.txt

  3. "Python27/Scripts/pip.exe install -r requirements.txt"

I resolved my issue by the @user4154243 answer, thanks for that.

Step 1: Add variable(if your path is not comes in variable's path).

Step 2: Go to command prompt, open oddo path where you installed.

Step 3: run this command python -m pip install XXX will run and installed the things.

Ajay2707
  • 5,690
  • 6
  • 40
  • 58
1

i solve my problem in Window if u install both python2 and python3

u need enter someone \Scripts change all file.exe to file27.exe,then it solve

my D:\Python27\Scripts edit django-admin.exe to django-admin27.exe so it done

decemer
  • 19
  • 1
1

My exact problem was (Fatal error in launcher: Unable to create process using '"') on windows 10. So I navigated to the "C:\Python33\Lib\site-packages" and deleted django folder and pip folders then reinstalled django using pip and my problem was solved.

Norman Pilusa
  • 337
  • 2
  • 5
1

On Windows I had solved this problem in the following way :

1) uninstalled Python

2) navigated to C:\Users\MyName\AppData\Local\Programs(your should turn on hidden files visibility Show hidden files instruction)

3) deleted 'Python' folder

4) installed Python

darkside
  • 47
  • 5
  • I am on Windows 10. I copied the python folder and overwrite to a new computer to save the time from installing everything of over 800 MBytes. This worked fine before, but somehow not this time. I tried everything here, only Darkside's ultimate solution works for me. – H.C.Chen May 17 '18 at 04:50
1

I have chosen to install Python for Windows (64bit) not for all users, but just for me.

Reinstalling Python-x64 and checking the advanced option "for all users" solved the pip problem for me.

Riki137
  • 2,076
  • 2
  • 23
  • 26
1

this worked for me

python -m pip install --upgrade --force-reinstall pip
Codertjay
  • 588
  • 8
  • 13
0

Try reinstall by using the below link,

Download https://bootstrap.pypa.io/get-pip.py

After download, copy the "get-pip.py" to python installed main dirctory, then open cmd and navigate to python directory and type "python get-pip.py" (without quotes)

Note: Also make sure the python directory is set in the environmental variable.

Hope this might help.

M.S. Arun
  • 1,053
  • 13
  • 22
0

For me this problem appeared when I changed the environment path to point to v2.7 which was initially pointing to v3.6. After that, to run pip or virtualenv commands, I had to python -m pip install XXX as mentioned in the answers below.

So, in order to get rid of this, I ran the v2.7 installer again, chose change option and made sure that, add to path option was enabled, and let the installer run. After that everything works as it should.

MrClan
  • 6,402
  • 8
  • 28
  • 43
0

I had this issue and the other fixes on this page didn't fully solve the problem.

What did solve the problem was going in to my system environment variables and looking at the PATH - I had uninstalled Python 3 but the old path to the Python 3 folder was still there. I'm running only Python 2 on my PC and used Python 2 to install pip.

Deleting the references to the nonexistent Python 3 folders from PATH in addition to upgrading to the latest version of pip fixed the issue.

Axesilo
  • 58
  • 1
  • 8
0

I had a simpler solution. Using @apple way but rename main.py to pip.py then put it in your python version scripts folder and add scripts folder to your path access it globally. if you don't want to add it to path you have to cd to scripts and then run pip command.

Sahib Khan
  • 557
  • 4
  • 19
0

I have similar problem when I reinstall my python, by uninstalling python3.7 and installing python3.8. But I solved it by removing the previous version of python directory. For me it was located here,

C:\Users\your-username\AppData\Local\Programs\Python

I deleted the folder named Python37 (for previous version) and keep Python38 (for updated version). This worked because python itself seems having a trouble on finding the right directory for your python scripts.

King
  • 164
  • 2
  • 13
0

I was trying to install some site-packages like numpy, xgboost and so on, but this error showed up every time:

Fatal error in launcher: Unable to create process using

I've tried many ways to solve this problem and found this one, that successfully helped me:

python -m pip freeze

Hope it'll help someone too.

P.S. I found this solution here: https://stackoverflow.com/a/39733705/10310794

Roman Voyt
  • 103
  • 2
  • 6
0

You can remove previous python folder and also environment variable path from you pc then Reinstall python .it will be solve

user8099291
  • 279
  • 1
  • 3
  • 12
0

I had this problem when using django rest framework and simplejwt. All I had to was upgrade pip and reinstall the packages

0

I had this problem today. The reason I was getting the error is because I have a project stored on Dropbox that I access from 2 different computers.

I am using venv, and because I had venv setup on machine A, if I attempted to run pytest on machine B I would get the error.

Deleting the venv folder, and running python -m venv venv solved the issue for me.

BugHunterUK
  • 8,346
  • 16
  • 65
  • 121
-2

Instead of calling ipython directly, it is loaded using Python such as

$ python "full path to ipython.exe"