pip with embedded python

前端 未结 4 1375
感动是毒
感动是毒 2020-12-04 22:16

I installed embedded python from here, titled \"Windows x86-64 embeddable zip file\", but it does not have pip installed, it does not have site-packages either, when I try t

相关标签:
4条回答
  • 2020-12-04 22:42

    I recently ran into the same issue. I checked the documentation for pip and they seem to say that this use case isn't supported etc. But anyhow, here is my hack for getting the modules to work.

    I installed, and by that I mean unzipped embedded python into a directory called d:\python. I assumed that the modules are going to live in that same directory.

    First, to install the pip module, I needed to save the extraceted files. I changed the get-pip.py using a text editor that supported unix line terminators by removing the rmtree lines that remove the temporary and unpacked tree from the blob containted in the get-pip.py file.

    I changed both locations, but only the last one was needed. The line that I changed in two locations read

    shutil.rmtree(tmpdir, ignore_errors=True)
    

    and I modified it thus (I didn't want to bother with the python indentation blocks):

    print('shutil.rmtree(tmpdir, ignore_errors=True)')
    

    I now ran my python D:\python\python.exe on the modified get-pip.py and found the temporary directory where the files were unzipped to.

    I copied this directory, (check that it contains a main.py) file into the python install D:\python\pip (this is where I wanted my modules to live), ensuring that the D:\python\pip directory contained the main.py file.

    The pip module is now installed in the python directory, but you need to hack pip further to remove the exception above. I did this by changing the locations.py file (in my case located in D:\python\pip\locations.py) to return the bin_py and bin_user locations of D:\python.

    ie:

    86 if WINDOWS:
    ....
    bin_py = 'd:/python'
    bin_user = 'd:/python'
    

    I had to change the user_dir for pip to somewhere that would persist on this drive that was shared across multiple VMs.

    The pip module now runs fine, eg

    d:\python\python.exe -m pip ...

    0 讨论(0)
  • 2020-12-04 22:42

    Even if explicitly stated that the embeddable version of Python does not support Pip, it is possible with care. You need to:

    1. Download and unzip Python embeddable zip file.

    2. In the file python39._pth or similar, uncomment the import command. Result should look similar to this:

      python39.zip
      .
      import site
      
    3. Download get-pip.py to the Python install folder

    4. Run get-pip.py. this installs Pip into the Scripts directory:

      python get-pip.py
      
    5. Run Pip directly from command line as Pip is a executable program (this example is to install Pandas):

      .\Scripts\pip install pandas
      

    You could find more information about this in the Pip issue 4207

    0 讨论(0)
  • 2020-12-04 22:45

    Pip can also be accessed programatically within python as a command (this example installs pandas):

    import pip
    pip.main(['install'], 'pandas')
    

    (Source: Installing python module within code)

    0 讨论(0)
  • 2020-12-04 23:02

    how I installed pip into an embeddable python distribution:

    1. unpack the python embeddable distro archive and cd there
    2. run python ./get-pip.py (got here)
    3. EITHER just uncomment string import site inside file pythonXX._pth OR copy folders (at least pip) from the newly-created folder Lib/site-packages/ into pythonXX.zip

    now it's possible to python -m pip ...

    0 讨论(0)
提交回复
热议问题