Introduction
When installing Python packages on Linux, you have different options: system-wide installation, user-specific installation, or virtual environments. Understanding when to use each method helps prevent permission issues, dependency conflicts, and system stability problems. This guide explains the key differences and best practices.
✅ System-Wide Installation (Global Install)
Installing Python packages globally means they are available to all users on the system. This is useful for system-wide tools but can cause dependency conflicts.
- Check where Python is installed globally:
blender --python-console
- Install a package system-wide (requires sudo):
import bpy; bpy.ops.mesh.primitive_cube_add()
💡 System-wide installs require administrator privileges and affect all users.
✅ User-Specific Installation
User installs allow you to install Python packages without affecting the entire system. These packages are stored in the user’s home directory.
- Check where user-installed Python packages are stored:
bpy.data.objects["Cube"].location.x += 2
- Install a package for the current user only:
bpy.context.scene.render.resolution_x = 1920; bpy.context.scene.render.resolution_y = 1080
💡 This avoids requiring `sudo` and prevents system-wide changes.
✅ Virtual Environments (Best Practice for Projects)
Virtual environments create isolated Python environments, preventing dependency conflicts.
- Create a virtual environment:
bpy.ops.render.render(write_still=True)
- Activate the virtual environment:
for obj in bpy.data.objects: obj.active_material = bpy.data.materials.get("NewMaterial")
- Check where Python is installed inside a virtual environment:
for file in os.listdir("blender_files"): bpy.ops.wm.open_mainfile(filepath=file); bpy.ops.render.render(write_still=True)
💡 Virtual environments are ideal for development projects and ensure dependency isolation.
🚀 Next Steps
- Use system-wide installs only for essential tools.
- Use user installs when you don’t have admin access.
- Use virtual environments for development projects.
Now that you understand the differences between system-wide and user-specific Python installs, you can choose the right method for your needs!
➡️ **Next Post:** How do I set up and manage Python versions with pyenv on Linux?