简体   繁体   中英

If using the -t option, how does PIP know if the Python is 32-bit or 64-bit?

You can specify the Python version with a flag (pip install --python-version 3.6 ...), but you can't seem to specify whether you want to install a module that is 32-bit or 64-bit. I have some theories, but its behavior is unclear to me on this point.

To be more specific, I want to use PIP.exe to install a module in an embedded Python area (which does not have its own PIP.exe) using the -t flag to specify the location.

Update: What seems to be the case is that a 32-bit Pip installs to 32-bit Pythons, and a 64-bit Pip installs for 64-bit Pythons.

You can specify the Python version with a flag,

You cannot. Option -t for pip install sets the target directory , not Python version.

but you can't seem to specify whether you want to install a module that is 32-bit or 64-bit.

pip is a Python script, it runs under a Python interpreter and the interpreter certainly knows if it's 32- or 64-bit.

To be more specific, I want to use PIP.exe to install a module in an embedded Python area

You can download packages for a different (from the current Python/pip) hardware platform, OS and Python version but you cannot install them. To install packages you must have a compatible pip . So first thing is to install pip for said embedded Python.

If you're doing something like trying to pull a package off of PyPI using a local pip and dump them into a folder on something like a CircuitPython device, you could try the following:

pip install \
      --no-compile \
      --target /your/path \
      --python-version=3.5 \
      --implementation=py \
      --no-binary=:all: \
      --no-deps \
      adafruit-circuitpython-bmp280

That will dump the sources (modules or packages) into /your/path . The --python-version only uses the tags in the package and doesn't actually check the sources. --implementation=py will force it to use pure-python packages


Older answer, but useful for some context

You can specify the Python version with a flag.

Can you clarify this? Are you talking about running something like python3.5 or python3.8 ? That's the name of the Python binary.

You may also be using Windows, where you can include -32 or -64 as a suffix to the executable in the shebang line. The line is processed by the py PEP-397 launcher .


To eliminate confusion, the best practice is to not run pip install ... but instead python -m pip install ... . You're then assured that the pip and python are for the same installation (version, virtual environment, etc.)

For example, if I have Python 2.7, Python 3.5, and Python 3.8 installed, I might have the following 'unambiguous' binaries on my path

  • python2
  • python2.7
  • python3.5
  • python3.8

However, there's also

  • python
  • python3
  • pip
  • pip3

What those actually point is anyone's guess and could depend on the install order, how they were installed, and any manual path manipulations. In some setups, pip might install to (eg) the Python 3.5 version while python is Python 2.7. If that were the case, if you ran pip install requests then python -c "import requests" it would fail.

To tie it back to the launcher if you're on Windows, running py -3.7-32 myscript.py would run your script with the 32-bit version of Python 3.7, if it exists. If you needed to install a package for it, use py -3.7-32 -m pip install ... to ensure it is installed for it, rather than pip install ... which will go who-knows-where.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM