python site-packages are not recognized after install (bug on linux / workes fine on Windows) #104000

Closed
opened 2023-01-19 13:34:52 +01:00 by Clemens Beute · 13 comments

System Information
Operating system: Linux-6.0.12-76060006-generic-x86_64-with-glibc2.35 64 Bits
Graphics card: NVIDIA GeForce RTX 2080 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.108.03

Blender Version
Broken: version: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash: 55485cb379
Worked: (3.0.0, not 100% shure)

Short description of error
I have an add-on that uses Pillow, so I would install Pillow to blenders Python.
This stopped working recently.
The add-on is installed (I checked, by looking into the site-packages folder and by executing blenders Python in a terminal -> outside of blender the import PIL works, in blender it doesn't)

The strangest thing is, that Pillow gets recognized, if you type:

help("modules")

pillow will work again, but will fail again, if you restart blender.

On Windows this bug doesn't exist.
Is this a bug on Linux builds, when blender tries to load its python site-packages?

Exact steps for others to reproduce the error
Open blender and go to the python console and type this:

import os
import sys
os.system(f'{sys.executable} -m ensurepip')
os.system(f'{sys.executable} -m pip install Pillow')
  • installation sould work fine, but if you try:

import PIL
  • you get an error

help("modules")
import PIL
  • now Pillow works like intended

System Information Operating system: Linux-6.0.12-76060006-generic-x86_64-with-glibc2.35 64 Bits Graphics card: NVIDIA GeForce RTX 2080 SUPER/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 510.108.03 Blender Version Broken: version: 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-19 17:00, hash: 55485cb379 Worked: (3.0.0, not 100% shure) **Short description of error** I have an add-on that uses Pillow, so I would install Pillow to blenders Python. This stopped working recently. The add-on is installed (I checked, by looking into the site-packages folder and by executing blenders Python in a terminal -> outside of blender the import PIL works, in blender it doesn't) The strangest thing is, that Pillow gets recognized, if you type: ``` help("modules") ``` pillow will work again, but will fail again, if you restart blender. On Windows this bug doesn't exist. Is this a bug on Linux builds, when blender tries to load its python site-packages? **Exact steps for others to reproduce the error** Open blender and go to the python console and type this: ``` import os ``` ``` import sys ``` ``` os.system(f'{sys.executable} -m ensurepip') ``` ``` os.system(f'{sys.executable} -m pip install Pillow') ``` - > installation sould work fine, but if you try: ``` import PIL ``` - > you get an error ``` help("modules") ``` ``` import PIL ``` - > now Pillow works like intended
Author

Added subscriber: @ClemensBeute

Added subscriber: @ClemensBeute
Member

Added subscriber: @lichtwerk

Added subscriber: @lichtwerk
Member

Dont forget the following (for someone that doesnt have pip yet), will include in the report.

os.system(f'{sys.executable} -m ensurepip')

Anyways, I cannot reproduce here (in both 3.0.0 and 3.4.1, also 3.5, I can import PIL right adter getting it...)

Dont forget the following (for someone that doesnt have pip yet), will include in the report. ``` os.system(f'{sys.executable} -m ensurepip') ``` Anyways, I cannot reproduce here (in both 3.0.0 and 3.4.1, also 3.5, I can import PIL right adter getting it...)

Added subscriber: @sebastian_k

Added subscriber: @sebastian_k

I can kind of confirm this.
Linux-6.0.12-76060006-generic-x86_64-with-glibc2.35 64 Bits
3.4.1, branch: blender-v3.4-release, commit date: 2022-12-20 08:50, hash: ef9ca44dee

Fresh install (download from buildbox, extract, ensurepip, pip install gspread), go to console, type "import gspread" -> module not found.
Type "help("modules")", type "import gspread" again and it works.

However, when I do the exact same thing on our server, it works!
Linux 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

It's so weird! So, could it be an OS kind of thing?

I can kind of confirm this. Linux-6.0.12-76060006-generic-x86_64-with-glibc2.35 64 Bits 3.4.1, branch: blender-v3.4-release, commit date: 2022-12-20 08:50, hash: `ef9ca44dee` Fresh install (download from buildbox, extract, ensurepip, pip install gspread), go to console, type "import gspread" -> module not found. Type "help("modules")", type "import gspread" again and it works. However, when I do the exact same thing on our server, it works! Linux 5.4.0-125-generic #141-Ubuntu SMP Wed Aug 10 13:42:03 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux It's so weird! So, could it be an OS kind of thing?

Added subscriber: @ideasman42

Added subscriber: @ideasman42

While I can't redo this, it seems likely the sys.path changes before & after running help("modules") could someone check if this is the case.

Also, can this problem be reproduced from a Python instance running outside of Blender?

While I can't redo this, it seems likely the `sys.path` changes before & after running `help("modules")` could someone check if this is the case. Also, can this problem be reproduced from a Python instance running outside of Blender?

Changed status from 'Needs Triage' to: 'Needs User Info'

Changed status from 'Needs Triage' to: 'Needs User Info'
Author

I checked it. In Blender sys.path changes after help("modules"), outside blender (running the blenders python executable) sys.path doesn't change.

But one other thing i noticed, is that numpy throws a warning:

- ! /home/silke/blender/blender_aktuell/3.4/python/lib/python3.10/pkgutil.py:92: UserWarning: The numpy.array_api submodule is still experimental. See NEP 47.
- !   __import__(info.name)

Here are the full console logs
blender_console.txt
system_console_blender_python.txt

I checked it. In Blender sys.path changes after help("modules"), outside blender (running the blenders python executable) sys.path doesn't change. But one other thing i noticed, is that numpy throws a warning: ``` - ! /home/silke/blender/blender_aktuell/3.4/python/lib/python3.10/pkgutil.py:92: UserWarning: The numpy.array_api submodule is still experimental. See NEP 47. - ! __import__(info.name) ``` Here are the full console logs [blender_console.txt](https://archive.blender.org/developer/F14186886/blender_console.txt) [system_console_blender_python.txt](https://archive.blender.org/developer/F14186887/system_console_blender_python.txt)

This is likely caused by Python not using the local environment by default: see 7c2f0074f3

Passing --python-use-system-env to Blender on startup should make Blender behave like regular Python.

This was an intentional change though, so we'd need to consider if including user site-packages by default is worth adding back, or if there are other alternatives.

This is likely caused by Python not using the local environment by default: see 7c2f0074f3 Passing `--python-use-system-env` to Blender on startup should make Blender behave like regular Python. This was an intentional change though, so we'd need to consider if including user site-packages by default is worth adding back, or if there are other alternatives.
Author

Ok, thank you. Starting blender with --python-use-system-env works for us.
But it seems like a workaround to me. As I understand, this gives Blender access to the system python modules.

I'm curious now, because I program add-ons for our company, and sometimes we need external modules...
Is there an official/correct way, how to use external python modules like Pillow in a blender add-on?

My approach was to install them with a command like this inside blender:

os.system(f'{sys.executable} -m pip install Pillow')
Ok, thank you. Starting blender with **--python-use-system-env** works for us. But it seems like a workaround to me. As I understand, this gives Blender access to the system python modules. I'm curious now, because I program add-ons for our company, and sometimes we need external modules... Is there an official/correct way, how to use external python modules like Pillow in a blender add-on? My approach was to install them with a command like this inside blender: ``` os.system(f'{sys.executable} -m pip install Pillow') ```

This issue was referenced by 72c012ab4a

This issue was referenced by 72c012ab4a3d2a7f7f59334f4912402338c82e3c

Changed status from 'Needs User Info' to: 'Resolved'

Changed status from 'Needs User Info' to: 'Resolved'
Campbell Barton self-assigned this 2023-01-25 02:53:16 +01:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#104000
No description provided.