pytest-blender
pytest-blender copied to clipboard
Cannot import pytest module on Windows 10
Hi,
On Windows cmd prompt after running
pytest --blender-executable "c:\Program Files\Blender Foundation\Blender 3.0\blender.exe" tests
I got an error saying
Blender 3.0.1 (hash dc2d18018171 built 2022-01-26 01:46:57)
Read prefs: C:\Users\karli\AppData\Roaming\Blender Foundation\Blender\3.0\config\userpref.blend
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\users\karli\appdata\local\programs\python\python38\lib\site-packages\pytest_blender\run_pytest.py", line 14, in <module>
import pytest
ModuleNotFoundError: No module named 'pytest'
Blender quit
Expand full command execution sequence :point_down:
- pytest-blender --blender-executable "c:\Program Files\Blender Foundation\Blender 3.0\blender.exe"
c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.EXE
- "c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.EXE" -m ensurepip
Defaulting to user installation because normal site-packages is not writeable Looking in links: c:\Users\karli\AppData\Local\Temp\tmprzsxnl8b Requirement already satisfied: setuptools in c:\program files\blender foundation\blender 3.0\3.0\python\lib\site-packages (57.4.0) Requirement already satisfied: pip in c:\program files\blender foundation\blender 3.0\3.0\python\lib\site-packages (21.2.3)
- "c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.EXE" -m pip install -r test-requirements.txt
Defaulting to user installation because normal site-packages is not writeable Requirement already satisfied: pytest in c:\users\karli\appdata\roaming\python\python39\site-packages (from -r test-requirements.txt (line 1)) (7.1.2) Requirement already satisfied: pytest-image-diff==0.0.9 in c:\users\karli\appdata\roaming\python\python39\site-packages (from -r test-requirements.txt (line 2)) (0.0.9) Requirement already satisfied: diffimg in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest-image-diff==0.0.9->-r test-requirements.txt (line 2)) (0.3.0) Requirement already satisfied: typing-extensions in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest-image-diff==0.0.9->-r test-requirements.txt (line 2)) (4.2.0)
Requirement already satisfied: imgdiff in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest-image-diff==0.0.9->-r test-requirements.txt (line 2)) (1.7.1) Requirement already satisfied: pluggy<2.0,>=0.12 in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (1.0.0) Requirement already satisfied: py>=1.8.2 in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (1.11.0) Requirement already satisfied: attrs>=19.2.0 in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (21.4.0) Requirement already satisfied: tomli>=1.0.0 in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (2.0.1) Requirement already satisfied: iniconfig in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (1.1.1) Requirement already satisfied: colorama in c:\program files\blender foundation\blender 3.0\3.0\python\lib\site-packages (from pytest->-r test-requirements.txt (line 1)) (0.4.4) Requirement already satisfied: packaging in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (21.3) Requirement already satisfied: atomicwrites>=1.0 in c:\users\karli\appdata\roaming\python\python39\site-packages (from pytest->-r test-requirements.txt (line 1)) (1.4.0) Requirement already satisfied: Pillow>=4.3 in c:\users\karli\appdata\roaming\python\python39\site-packages (from diffimg->pytest-image-diff==0.0.9->-r test-requirements.txt (line 2)) (9.1.1)
Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in c:\users\karli\appdata\roaming\python\python39\site-packages (from packaging->pytest->-r test-requirements.txt (line 1)) (3.0.9)
WARNING: You are using pip version 21.2.3; however, version 22.1.2 is available. You should consider upgrading via the 'c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.exe -m pip install --upgrade pip' command.
I was wondering if it is related to the phrase:
Defaulting to user installation because normal site-packages is not writeable
Could you execute c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\bin\python.EXE -c 'import site;print(site.getsitepackages())'
? That should show c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\lib\site-packages
, from which the installed packages must be discovered. Not sure how works the permissions in Windows, but I suppose that your user must have writing permissions for that directory. If so, ensure that python.EXE
is not a symlink pointing to another version of Python installed in your system.
If none of the above works, just to be sure, how do you've installed Blender, using a MSI installer or decompressing a ZIP file?
By running python and executing that command it returned string you anticipated
['c:\Program Files\Blender Foundation\Blender 3.0\3.0\python', 'c:\Program Files\Blender Foundation\Blender 3.0\3.0\python\lib\site-packages']
Not sure how works the permissions in Windows, but I suppose that your user must have writing permissions for that directory.
Unfortunately neither do I. I did try running [..] pip install -r test-requirements.txt
via cmd prompt that has been run as administrator - no Luck.
Also python.exe
doesn't seem to be symlinked
Answering your last question - I usually grab an MSI installer. I am a bit clueless about how to proceed. Is it right that pytest_blender is called from appdata?
File "c:\users\karli\appdata\local\programs\python\python38\lib\site-packages\pytest_blender\run_pytest.py", line 14, in
I will investigate it. As a workaround you can try blender-downloader which downloads a portable release of blender or directly download the ZIP portable version of blender from official repositories. I hadn't experienced problems with portable releases in the past on Windows, but maybe this problem also appears on your system.
Note for myself, maybe this kind of logic would work?
Hi, I got the same problem with Blender3.0 today.
In my case, -t
option fixed the error.
The cause was pytest would be in C:\users\xxx\appdata\...
.
(It should be installed in Blender's python folder like ...\3.0\python\lib\site-packages
)
I installed Blender to D:\Blender3.0
.
So, I used this batch file.
set BLENDER=D:\Blender3.0
set PYTHON_EXE=%BLENDER%\3.0\python\bin\python.exe
set SITE_PACK=%BLENDER%\3.0\python\lib\site-packages
"%PYTHON_EXE%" -m ensurepip
"%PYTHON_EXE%" -m pip install pytest -t "%SITE_PACK%"
Then, pytest passed this test script.
import pytest
def test_1():
import bpy
assert 'bpy' in locals()
I didn't investigate it further, but it is good to know that this works (will try it later). I got a step further (the workaround) by downloading Blender using blender-downloader as suggested.