Pants include OS X specific Python wheels

TL; DR : pants choose OS X special wheels. Bc I am developing on a Mac. How can I avoid this or indicate that I will use Ubuntu?

Full story :

Trying to package a Python application using Pants. It’s still great, but I ran into a problem that I’ve been stuck for a while. I am developing on a macbook, but implementing on Ubuntu EC2.

Here is what I have done so far:

  • Created by virtualenv.
  • Added BUILD files for applications with the proposed third-party template for third-party packages.
  • Ran ./pants run.py backend:admin_serverthat works fine and generateddist/admin_server.pex
  • Scp that .pex on the new EC2 Ubuntu field.

However, when I launch the application, I get:

Failed to execute PEX file, missing compatible dependencies for:
    mysql-python
    pycrypto

, , OS X 2:

pex: - MySQL_python-1.2.5-cp27-none-macosx_10_11_intel.whl pex: - pycrypto-2.6.1-cp27-none-macosx_10_11_intel.whl

, ?

:

ubuntu@ip-***:~$ export PEX_VERBOSE=1
ubuntu@ip-***:~$ python admin_server.pex
pex: Found site-library: /usr/local/lib/python2.7/dist-packages
pex: Found site-library: /usr/lib/python2.7/dist-packages
pex: Tainted path element: /usr/local/lib/python2.7/dist-packages
pex: Tainted path element: /usr/lib/python2.7/dist-packages
pex: Scrubbing from site-packages: /usr/local/lib/python2.7/dist-packages
pex: Scrubbing from site-packages: /usr/lib/python2.7/dist-packages
pex: Scrubbing from user site: /home/ubuntu/.local/lib/python2.7/site-packages
pex: Failed to resolve a requirement: MySQL-python==1.2.5
pex: Failed to resolve a requirement: pycrypto==2.6.1
pex: Unresolved requirements:
pex:   - mysql-python
pex:   - pycrypto
pex: Distributions contained within this pex:
pex:   - six-1.10.0-py2.py3-none-any.whl
pex:   - protobuf-2.6.1-py2.7.egg
pex:   - setuptools-19.5-py2.py3-none-any.whl
pex:   - MySQL_python-1.2.5-cp27-none-macosx_10_11_intel.whl
pex:   - pycrypto-2.6.1-cp27-none-macosx_10_11_intel.whl
pex:   - futures-3.0.4-py2-none-any.whl
pex:   - webapp2-2.5.2-py2-none-any.whl
pex:   - requests-2.9.0-py2.py3-none-any.whl
pex:   - jmespath-0.9.0-py2.py3-none-any.whl
pex:   - beautifulsoup4-4.4.1-py2-none-any.whl
pex:   - python_dateutil-2.4.2-py2.py3-none-any.whl
pex:   - boto3-1.2.3-py2.py3-none-any.whl
pex:   - WebOb-1.5.1-py2.py3-none-any.whl
pex:   - cssutils-1.0.1-py2-none-any.whl
pex:   - webapp2_static-0.1-py2-none-any.whl
pex:   - Paste-2.0.2-py2-none-any.whl
pex:   - docutils-0.12-py2-none-any.whl
pex:   - botocore-1.3.22-py2.py3-none-any.whl
pex:   - protobuf_to_dict-0.1.0-py2-none-any.whl
Failed to execute PEX file, missing compatible dependencies for:
mysql-python
pycrypto

PS: python, PyKrypto MySQL-Python.

+4
1

PEX , . , PEX Linux, Mac. , PEX. , , .

, , , psutil. C, . PEX, , , , .

- pip .

:

  • pex Linux Mac Linux, PEX Mac.
  • ~/src/cookbook

, pex.

#  src/python/ps_example/main.py
import psutil

for proc in psutil.process_iter():
    try:
        pinfo = proc.as_dict(attrs=['pid', 'name'])
    except psutil.NoSuchProcess:
        pass
    else:
        print(pinfo)

Pants , python_binary target BUILD:

# src/python/ps_example/BUILD
python_binary(name='ps_example',
  source = 'main.py',
  dependencies = [
    ':psutil',  # defined in requirements.txt
  ],
)

# Defines targets from specifications in requirements.txt
python_requirements()

python requirements.txt:

# src/python/ps_example/requirements.txt 
psutil==3.1.1

, pex, Linux, psutil Linux. requirements.txt linux, pip:

linux $ mkdir ~/src/cookbook/wheelhouse
linux $ pip wheel -r src/python/multi-platform/requirements.txt  \
    --wheel-dir=~/src/cookbook/wheelhouse

.

linux $ ls ~/src/cookbook/wheelhouse/
psutil-3.1.1-cp27-none-linux_x86_64.whl

, pex ( Mac-). , , , Python .

BUILD, , python_binary, platforms=.

# src/python/ps_example/BUILD
python_binary(name='ps_example',
  source = 'main.py',
  dependencies = [
    ':psutil',  # defined in requirements.txt
  ],
  platforms=[
    'linux-x86_64',
    'macosx-10.7-x86_64',
  ],
)

# Defines targets from specifications in requirements.txt
python_requirements()

, python. pants.ini :

[python-repos]
repos: [
    "%(buildroot)s/wheelhouse/"
  ]

psutil-3.1.1-cp27-none-linux_x86_64.whl ​​Mac wheelhouse/ .

, pex

mac $ ./pants binary src/python/py_example

, Mac Linux pex, :

mac $ unzip -l dist/ps_example.pex | grep psutil
    17290  12-21-15 22:09   .deps/psutil-3.1.1-cp27-none-linux_x86_64.whl/psutil-3.1.1.dist-info/DESCRIPTION.rst
    19671  12-21-15 22:09   .deps/psutil-3.1.1-cp27-none-linux_x86_64.whl/psutil-3.1.1.dist-info/METADATA
     1340  12-21-15 22:09   .deps/psutil-3.1.1-cp27-none-linux_x86_64.whl/psutil-3.1.1.dist-info/RECORD
      103  12-21-15 22:09  
...   .deps/psutil-3.1.1-cp27-none-macosx_10_11_intel.whl/psutil-3.1.1.dist-info/DESCRIPTION.rst
    19671  12-21-15 22:09   .deps/psutil-3.1.1-cp27-none-macosx_10_11_intel.whl/psutil-3.1.1.dist-info/METADATA
     1338  12-21-15 22:09   .deps/psutil-3.1.1-cp27-none-macosx_10_11_intel.whl/psutil-3.1.1.dist-info/RECORD
      109  12-21-15 22:09   
...
+10

Source: https://habr.com/ru/post/1625733/


All Articles