Azure Ubuntu 16.04虚拟机中升级Python3.5至Python3.6的方法及JupyterLab可行性咨询
Hey there! Let's fix that "unable to locate package" error and get Python 3.6 set up on your VM, plus cover how to handle this with JupyterLab:
Why apt-get can't find Python 3.6?
Ubuntu 16.04's default software repositories don't include Python 3.6 out of the box. You'll need to add a trusted third-party PPA (Personal Package Archive) that hosts older/newer Python versions—deadsnakes is the standard choice for this.
Method 1: System-wide install via APT
Follow these steps to get Python 3.6 working with apt:
- Add the deadsnakes PPA to your system:
Press Enter when prompted to confirm adding the repository.sudo add-apt-repository ppa:deadsnakes/ppa - Update your package lists to pull in the new PPA's contents:
sudo apt-get update - Install Python 3.6:
This should resolve the package not found error now.sudo apt-get install python3.6
Optional: Set Python 3.6 as default python3
If you want python3 to point to 3.6 instead of the original 3.5, use the update-alternatives tool:
# Register both versions with priority levels sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1 sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2 # Select which version to use by default sudo update-alternatives --config python3
Just enter the number corresponding to Python 3.6 when prompted, and you're done.
Method 2: Install via Anaconda (Recommended for your setup)
Since your current Python is from Anaconda, creating a dedicated environment with Python 3.6 is safer (it won't mess with your system's default Python):
- Create a new conda environment with Python 3.6:
conda create -n py36 python=3.6 - Activate the environment to start using Python 3.6:
Now runningsource activate py36python --versionwill show Python 3.6 in this environment.
Can you do this via JupyterLab?
Absolutely! Here's how to add your Python 3.6 environment as a Jupyter kernel:
For conda environments:
- Activate your
py36environment first:source activate py36 - Install the
ipykernelpackage to connect the environment to Jupyter:conda install ipykernel - Register the environment as a Jupyter kernel:
python -m ipykernel install --user --name py36 --display-name "Python 3.6 (py36)" - Restart JupyterLab, and you'll see the "Python 3.6 (py36)" option in the kernel launcher.
For APT-installed Python 3.6:
- Install required tools for kernel setup:
sudo apt-get install python3.6-dev python3.6-pip pip3.6 install ipykernel - Register the kernel:
Restart JupyterLab, and the new kernel will be available.python3.6 -m ipykernel install --user --name python36 --display-name "Python 3.6"
内容的提问来源于stack exchange,提问作者blackraven

