无法将Python库从一台电脑转移至另一台,求手动迁移方案
Got it, let's walk through how to manually transfer that Python library from your first PC to the second one when pip isn't cooperating. This guide is tailored for PyCharm users, so it should fit right into your workflow:
Wheel files are pre-compiled Python packages that let you install libraries without relying on pip to download them. Here's how to grab the exact version from your first computer:
- Open Command Prompt (Windows) or Terminal (macOS/Linux) on your original PC. If you used a virtual environment in PyCharm for this library, activate it first:
- Windows:
venv\Scripts\activate(navigate to your project's folder first if needed) - macOS/Linux:
source venv/bin/activate
- Windows:
- Run this command to generate the wheel file for your target library. Replace
your-library-namewith the actual name of the package:
This will save the library (and any dependencies it needs) aspip wheel your-library-name -w ./wheel-exports.whlfiles in a folder calledwheel-exports. If you already have dependencies installed on the second PC, add--no-depsto skip downloading them:pip wheel your-library-name --no-deps -w ./wheel-exports - Locate the
wheel-exportsfolder—you'll see one or more.whlfiles here; these are the packages you need to transfer.
Use a USB drive, cloud storage, or a local network share to copy all the .whl files from the wheel-exports folder to an easy-to-find spot on your second PC (e.g., a folder on the desktop named transferred-packages).
You can install the package either through PyCharm's graphical interface or via the terminal—pick whichever you prefer:
Option 1: PyCharm GUI Installation
- Open your project in PyCharm, then go to
File > Settings > Project: [Your Project Name] > Python Interpreter(on macOS, this isPyCharm > Settings > Project: [Your Project Name] > Python Interpreter). - Click the
+button in the top-right corner of the interpreter window. - Select
Install from diskfrom the options that pop up. - Browse to the folder where you saved the
.whlfiles, select the correct one for your library, and clickOK. Wait for the installation to finish, then clickApplyandOKto close the settings.
Option 2: Terminal Installation (Faster for Multiple Packages)
- Open the Terminal tab at the bottom of your PyCharm window.
- Activate your project's virtual environment (same command as Step 1):
- Windows:
venv\Scripts\activate - macOS/Linux:
source venv/bin/activate
- Windows:
- Navigate to the folder with your transferred
.whlfiles. For example:cd C:\Users\YourUsername\Desktop\transferred-packages - Install the library with this command (replace
your-library-file.whlwith the actual filename):
If you have multiple dependency wheel files to install, you can install all of them at once:pip install your-library-file.whlpip install *.whl
To make sure everything worked, check the Python Interpreter list in PyCharm—you should see the library listed with the exact version from your original PC. Alternatively, run this in the terminal:
pip show your-library-name
It should display the version number matching what you had on the first computer.
内容的提问来源于stack exchange,提问作者Guy Katabi

