Could not create Python virtual environment

I'm getting error while using rosinit. When i was using python 3.8 i got:
Launching ROS Core...
Could not find Python version 2.7 on your system. Use pyenv function to set the path
to the Python 2.7 executable.
After switching to 2.7 i got this error:
Could not create Python virtual environment. 'C:\Users\User
Name\AppData\Roaming\MathWorks\MATLAB\R2021a\ros1\win64\venv\Scripts\python.exe' is
not found. Verify installation of Python in your system and re-create the Python
virtual environment.

답변 (3개)

Benjamin William Brokaw
Benjamin William Brokaw 2021년 4월 22일

1 개 추천

I was struggling with this problem for so long and it seems we are the only ones having this issue.
What ended up working for me was pip installing virtualenv and then creating a virtual python enviornment with 'virtualenv tmpenv' .
Next I coppied the contents of tmpenv over to AppData\Roaming\MathWorks\MATLAB\R2021a\ros1\win64\venv\
I had to create this outside of \venv\ because of the way the createOrGetLocalPython.m script works. There is a command to create the directory win64/venv/temp that will error out if the parent folders already exist.
I beleive the culprit is line 135 in createOrGetLocalPython.m:
[stat, res] = system(['"' pyexec '" ' fullfile(tempPythonExtractDir,'virtualenv-16.6.1','virtualenv.py') ' --no-setuptools --no-pip --no-wheel ' pyenvDir ' --system-site-packages']);
This line should setup the env for us, but in my case it was returning success but not actually creating it.
Hope this helps!

댓글 수: 3

I had a similar issue.
I traced the problem back to line 62 of createOrGetLocalPython.m:
if isempty(venvRoot)
if ismac
venvRoot = fullfile(getenv('HOME'),'.matlab',['R' version('-release')]); %on Mac's using prefdir causes several issues due to space in folder names
else
venvRoot = prefdir;
end
end
For my windows 10 install, relyng on prefdir means that venvRoot ends up with the value
'C:\Users\User Name\AppData\Roaming\MathWorks\MATLAB\R2021b'
The space in the `User Name` subdirectory causes issues when running system calls on line 135, as the space character is not properly escaped.
As a workaround, I put a breakpoint on line 140 then ran the following before continuing
cmd = ['"' pyexec '" ' '"' fullfile(tempPythonExtractDir,'virtualenv-16.6.1','virtualenv.py') '"' ' --no-setuptools --no-pip --no-wheel ' '"' pyenvDir '"' ' --system-site-packages']
[stat, res] = system(cmd);
This seemed to solve the issue.
Hi Robert,
I have similar issue. Please I need your help.
Creating a Python virtual environment...Done.
Error using ros.internal.createOrGetLocalPython
Could not create Python virtual environment.
in Matlab

댓글을 달려면 로그인하십시오.

Murat Belge
Murat Belge 2022년 6월 29일

1 개 추천

ROS Toolbox creates a Python virtual environment in user's prefdir by default. If your user name contains spaces and this gets reflected in prefdir, this will create issues with Python virtual environment generation and later on with custom message generation, etc. To work around this, set 'MY_PYTHON_VENV' environment variable to a directory without spaces and run ros.internal.createOrGetLocalPython function as in the following:
>> setenv('MY_PYTHON_VENV','C:\temp\venv')
>> ros.internal.createOrGetLocalPython(true)
This will use 'C:\temp\venv' as the root directory for Python virtual environment.

댓글 수: 1

Minor update to the above Answer. For R2021a relase, The environment variable that has to be set is 'MY_PYTHON2_VENV'.
For the Release older than R2022a, Please execute these commands below and then run ros.internal.createOrGetLocalPython(true) function:
>> setenv('MY_PYTHON2_VENV','C:\temp\venv')
>> ros.internal.createOrGetLocalPython(true)
From R2022a onwards:
>> setenv('MY_PYTHON_VENV','C:\temp\venv')
>> ros.internal.createOrGetLocalPython(true)
Thanks
Hari

댓글을 달려면 로그인하십시오.

Ricardo Antunes
Ricardo Antunes 2023년 7월 6일

0 개 추천

Nothing worked on 2023a.
I created a virtual env using python 3.9 (latest compatible with ROS toolbox at this point).
The pointed the ROS toolbox to the python on that envoirement. It worked fine.

카테고리

도움말 센터File Exchange에서 Call Python from MATLAB에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 3월 31일

답변:

2023년 7월 6일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by