Ubuntu下Python最佳安装方式抉择:Conda、系统版或虚拟环境?
Hey there! Let's break down your questions one by one, since you're switching to Ubuntu 18.04 for Nuke scripting and PySide/PyQt GUI development—super relatable, I've been in that boat too.
Short answer: Absolutely not.
Ubuntu’s preinstalled Python 2.7 and 3.6 are tightly integrated with the system—many core tools (like apt, dpkg, and system configuration scripts) rely on them. Installing or updating packages directly on these system Python instances can break dependencies, lead to version conflicts, and even render parts of your OS unresponsive.
The safe approach is to keep the system Python completely "clean" and use isolated environments for your development work.
First, a key point: Python 2 and 3 are fundamentally separate runtime environments. Modules installed for one version won’t be accessible to the other—this is intentional, since the two versions have incompatible syntax and library structures. Here’s how to manage them effectively:
Installing modules for each version
Ubuntu 18.04 comes with pip2 (for Python 2.7) and pip3 (for Python 3.6) preinstalled. Use these to target each version explicitly:
- For Python 2.7 (e.g., Nuke scripting, which often uses Python 2):
pip2 install pyside numpy - For Python 3.x (e.g., PyQt GUI development):
pip3 install pyside2 pyqt5
Bulk updating packages
To update all outdated packages for each version, you can use these one-liners:
- For Python 2.7:
pip2 list --outdated | grep -v "^-" | cut -d " " -f 1 | xargs -n1 pip2 install -U - For Python 3.6:
pip3 list --outdated | grep -v "^-" | cut -d " " -f 1 | xargs -n1 pip3 install -U
Even better: Use virtual environments
For cleaner separation (e.g., a dedicated environment for Nuke vs. your GUI project), use virtualenv:
- Install it first:
sudo apt install virtualenv - Create a Python 2.7 environment for Nuke:
virtualenv -p /usr/bin/python2.7 nuke_dev_env - Activate it (this isolates your package installs to this environment):
source nuke_dev_env/bin/activate - Install your Nuke-related packages here with
pip(notpip2, since the environment is tied to Python 2.7) - Repeat for Python 3.x:
virtualenv -p /usr/bin/python3.6 pyqt_gui_env source pyqt_gui_env/bin/activate pip install pyside2
Both tools solve the core problem of dependency hell, but they have slightly different strengths:
Virtualenv (and its modern cousin venv)
- Lightweight environment isolation: Creates a self-contained Python environment with its own
pipand package directory. No impact on system Python or other environments. - Perfect for Python-only projects: Great for scripting (like Nuke tools) or GUI apps where all dependencies are Python-based.
- Easy to set up: Minimal overhead, works directly with Ubuntu’s system Python versions.
Conda
- Cross-language dependency management: Unlike
pip, Conda can install non-Python libraries (e.g., compiled C/C++ dependencies for GUI frameworks or image processing tools). This is a huge win for Nuke development, where you might need specific versions of image libraries that are hard to compile on Ubuntu 18.04. - Built-in multi-version support: Conda lets you create environments with any Python version (not just the system ones). If Nuke requires Python 2.7.15 specifically, or your GUI project needs Python 3.8 instead of 3.6, Conda can handle that without messing with your system.
- Simpler bulk updates: Instead of messy pip one-liners, you can update all packages in a Conda environment with a single command:
conda update --all - Reproducibility: Conda environments can be exported to a YAML file, making it easy to share your exact dependency setup with others or replicate it on another machine.
内容的提问来源于stack exchange,提问作者Nub

