带有嵌入式python的pip [英] pip with embedded python
问题描述
我从此处安装了嵌入式python,标题为"Windows x86-64可嵌入的zip文件",但它没有安装pip,也没有站点包,当我尝试执行python get-pip.py
时,它运行失败,因为此文件中包含import pip
.那么如何在嵌入式python环境中安装pip.
回溯(最近通话最近): 文件.\ getpip.py"在第20061行中 主要的() 主文件.\ getpip.py",第194行 引导程序(tmpdir = tmpdir) 引导程序中的文件.\ getpip.py",第82行 进口点 _find_and_load中的文件",第961行 _find_and_load_unlocked中的文件",行950 文件",行_load_unlocked中的第646行 _load_backward_compatible
中的文件",第616行
目录结构为:
Directory: C:\Downloads\python-3.6.1rc1-embed-win32
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/4/2017 7:26 PM 157344 pyexpat.pyd
-a---- 3/4/2017 7:26 PM 97952 python.exe
-a---- 3/4/2017 7:26 PM 58016 python3.dll
-a---- 3/4/2017 7:26 PM 3263648 python36.dll
-a---- 3/4/2017 7:26 PM 2209284 python36.zip
-a---- 3/4/2017 7:26 PM 79 python36._pth
-a---- 3/4/2017 7:26 PM 96416 pythonw.exe
-a---- 3/4/2017 7:26 PM 23200 select.pyd
-a---- 3/4/2017 7:26 PM 866464 sqlite3.dll
-a---- 3/4/2017 7:26 PM 895648 unicodedata.pyd
-a---- 3/4/2017 7:26 PM 83784 vcruntime140.dll
-a---- 3/4/2017 7:26 PM 24224 winsound.pyd
-a---- 3/4/2017 7:26 PM 45216 _asyncio.pyd
-a---- 3/4/2017 7:26 PM 77984 _bz2.pyd
-a---- 3/4/2017 7:26 PM 101536 _ctypes.pyd
-a---- 3/4/2017 7:26 PM 215712 _decimal.pyd
-a---- 3/4/2017 7:26 PM 156832 _elementtree.pyd
-a---- 3/4/2017 7:26 PM 1042592 _hashlib.pyd
-a---- 3/4/2017 7:26 PM 183456 _lzma.pyd
-a---- 3/4/2017 7:26 PM 32416 _msi.pyd
-a---- 3/4/2017 7:26 PM 25760 _multiprocessing.pyd
-a---- 3/4/2017 7:26 PM 33952 _overlapped.pyd
-a---- 3/4/2017 7:26 PM 61600 _socket.pyd
-a---- 3/4/2017 7:26 PM 64160 _sqlite3.pyd
-a---- 3/4/2017 7:26 PM 1458848 _ssl.pyd
我最近遇到了同一问题.我检查了pip的文档,他们似乎说不支持该用例,等等.但是,无论如何,这是使模块正常工作的秘诀.
我安装了,意思是将嵌入式python解压缩到名为d:\ python的目录中.我以为这些模块将位于同一目录中.
首先,要安装pip模块,我需要保存引用的文件.我通过使用支持 unix 行终止符的文本编辑器更改了get-pip.py,方法是删除rmtree行,该行删除了get-pip.py文件中包含的blob中的临时树和解包树. /p>
我更改了两个位置,但只需要最后一个.我在两个位置更改的行读为
shutil.rmtree(tmpdir, ignore_errors=True)
然后我进行了修改(我不想打扰python缩进块):
print('shutil.rmtree(tmpdir, ignore_errors=True)')
我现在在修改后的get-pip.py上运行我的python D:\ python \ python.exe,并找到了将文件解压缩到的临时目录.
我将此目录复制了(检查其中是否包含主 .py)文件到python install D:\ python \ pip(这是我希望模块保留的位置),确保D:\ python \ pip目录包含主 .py文件.
pip模块现在已安装在python目录中,但是您需要进一步破解pip才能删除上述异常.我通过更改location.py文件(在我的情况下位于D:\ python \ pip \ locations.py中)来返回D:\ python的bin_py和bin_user位置来完成此操作.
即:
86 if WINDOWS:
....
bin_py = 'd:/python'
bin_user = 'd:/python'
我必须将pip的user_dir更改为该驱动器上持久存在的某个位置,该驱动器已在多个VM上共享.
pip模块现在可以正常运行,例如
d:\ python \ python.exe -m pip ...
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 to do python get-pip.py
it failed to run because this file has import pip
in it. So how can I install pip within a embedded python environment.
Traceback (most recent call last): File ".\getpip.py", line 20061, in main() File ".\getpip.py", line 194, in main bootstrap(tmpdir=tmpdir) File ".\getpip.py", line 82, in bootstrap import pip File "", line 961, in _find_and_load File "", line 950, in _find_and_load_unlocked File "", line 646, in _load_unlocked File "", line 616, in _load_backward_compatible
The directory structure is:
Directory: C:\Downloads\python-3.6.1rc1-embed-win32
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 3/4/2017 7:26 PM 157344 pyexpat.pyd
-a---- 3/4/2017 7:26 PM 97952 python.exe
-a---- 3/4/2017 7:26 PM 58016 python3.dll
-a---- 3/4/2017 7:26 PM 3263648 python36.dll
-a---- 3/4/2017 7:26 PM 2209284 python36.zip
-a---- 3/4/2017 7:26 PM 79 python36._pth
-a---- 3/4/2017 7:26 PM 96416 pythonw.exe
-a---- 3/4/2017 7:26 PM 23200 select.pyd
-a---- 3/4/2017 7:26 PM 866464 sqlite3.dll
-a---- 3/4/2017 7:26 PM 895648 unicodedata.pyd
-a---- 3/4/2017 7:26 PM 83784 vcruntime140.dll
-a---- 3/4/2017 7:26 PM 24224 winsound.pyd
-a---- 3/4/2017 7:26 PM 45216 _asyncio.pyd
-a---- 3/4/2017 7:26 PM 77984 _bz2.pyd
-a---- 3/4/2017 7:26 PM 101536 _ctypes.pyd
-a---- 3/4/2017 7:26 PM 215712 _decimal.pyd
-a---- 3/4/2017 7:26 PM 156832 _elementtree.pyd
-a---- 3/4/2017 7:26 PM 1042592 _hashlib.pyd
-a---- 3/4/2017 7:26 PM 183456 _lzma.pyd
-a---- 3/4/2017 7:26 PM 32416 _msi.pyd
-a---- 3/4/2017 7:26 PM 25760 _multiprocessing.pyd
-a---- 3/4/2017 7:26 PM 33952 _overlapped.pyd
-a---- 3/4/2017 7:26 PM 61600 _socket.pyd
-a---- 3/4/2017 7:26 PM 64160 _sqlite3.pyd
-a---- 3/4/2017 7:26 PM 1458848 _ssl.pyd
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 ...
这篇关于带有嵌入式python的pip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!