Ryan Doherty Ryan Doherty - 7 months ago 14
Python Question

`pip install pygments` incomplete install when run as build phase in XCode

I am running the command:

pip -v install pygments==2.0.2 --force-reinstall --ignore-installed --target .


as part of my build process in a Kivy iOS project. When I run the command myself in the terminal, pygments is installed correctly. When XCode runs it, the pygments package does not install any files in the
pygments/formatters
directory.

I have verified that the same pip is used for my user and when XCode runs
pip
.

Output when I install pygments:

(rdoherty.local) %% pip -v install pygments==2.0.2 --force-reinstall --ignore-installed --target . ~/Documents/projects/kivy-ios/racecapture-ios/YourApp (master)
Downloading/unpacking pygments==2.0.2
Could not fetch URL https://pypi.python.org/simple/pygments/2.0.2: 404 Client Error: Not Found
Will skip URL https://pypi.python.org/simple/pygments/2.0.2 when looking for download links for pygments==2.0.2
[snip]
Using version 2.0.2 (newest of versions: 2.0.2, 2.0.2)
Downloading Pygments-2.0.2-py2-none-any.whl (672kB):
Downloading from URL https://pypi.python.org/packages/2.7/P/Pygments/Pygments-2.0.2-py2-none-any.whl#md5=98f29db02f4b22f58a2d3f60646e1e1f (from https://pypi.python.org/simple/pygments/)
...Downloading Pygments-2.0.2-py2-none-any.whl (672kB): 672kB downloaded
Installing collected packages: pygments
Successfully installed pygments


Output when Xcode runs the exact same command:

Downloading/unpacking pygments==2.0.2
Could not fetch URL https://pypi.python.org/simple/pygments/2.0.2: 404 Client Error: Not Found
[snip]
Using version 2.0.2 (newest of versions: 2.0.2, 2.0.2)
Downloading from URL https://pypi.python.org/packages/2.7/P/Pygments/Pygments-2.0.2-py2-none-any.whl#md5=98f29db02f4b22f58a2d3f60646e1e1f (from https://pypi.python.org/simple/pygments/)
Installing collected packages: pygments
Successfully installed pygments


I have downloaded the file that pip downloads and verified it contains files in the
formatters
directory. I have verified that the same
pip
program is being used for both myself and XCode:

(rdoherty.local) %% which pip ~/Documents/projects/kivy-ios/racecapture-ios/YourApp (master)
/usr/local/bin/pip


How or why would pip incorrectly unzip or install pygments when run in an Xcode build phase vs directly?

Answer

This was a PEBKAC issue. Kivy iOS projects have a few default build steps and one of them is to delete all *.py files in your app's directory. Normally this is fine because there is a step before this that compiles all the .py files to .pyc. But my build steps had the pip install command running after the compilation step. So all .py files were being removed inside the Pygments directory before they were compiled to .pyc.