Ubuntu16.04下Python3.6无法使用已安装的numpy问题求助
Hey there! Let's sort out why numpy works in Python 3.5 but not 3.6 on your Ubuntu system. The core issue here is that your default pip3 is tied to Python 3.5, so any packages you install with it only end up in Python 3.5's library folder. Here are simple, reliable fixes:
1. Install numpy directly for Python 3.6 using python -m pip
This is the most foolproof method because it explicitly uses the pip associated with your target Python version:
- First, check if Python 3.6 has pip installed:
python3.6 -m pip --version - If you get an error saying pip isn't found, install it first with:
sudo apt-get update && sudo apt-get install python3.6-pip - Now install numpy specifically for Python 3.6:
python3.6 -m pip install numpy
2. Use the version-specific pip command
Once you have python3.6-pip installed, your system should have a pip3.6 command. You can use this directly to install numpy:
pip3.6 install numpy
3. Verify the installation worked
To make sure numpy is now accessible in Python 3.6, run this quick test:
python3.6 -c "import numpy; print('Numpy version:', numpy.__version__)"
If you see the version number printed out, you're good to go!
Pro Tip
Going forward, always use pythonX.Y -m pip install <package> (replace X.Y with your target Python version) to avoid mixing up packages between different Python installations. This keeps your environments clean and avoids version conflicts.
内容的提问来源于stack exchange,提问作者Subhojeet

