PyROOT in Visual studo help

_ROOT Version:latest one
_Platform:visual microsoft studios 2022
_Compiler:python 3.10


Import root isnt working in visual studios. From what ive read, Pyroot should be included in ROOT. Is visual studios special where i need to do something else?

Welcome to the ROOT Forum!

You must set the ROOTSYS environment variable to the location of ROOT is installed, add %ROOTSYS%\bin to your PATH environment variable, and add %ROOTSYS%\bin in PYTHONPATH (create it if it doesn’t exist)

where the do i find the rootsys eviroment variable?

You must create it in your environment or in your system. But now I have a question: why do you want to run python from Visual Studio?

because its what i have for running python, and the project im working on is done with pyroot

I have no idea how to create an enviroment variable

OK, so you don’t need to start from Visual Studio. Can you tell me the exact version of ROOT you installed? 64 bit or 32 bit? And which version of Python do you have on your system?

root 6.28 32-bit binary for visual studio and python 3.1 32 bit. Hold on i misread something and downloaded a debug version, that might be whats wrong
Further update: my windows doesnt “recognize” non debug root exe and doesnt want to run it. love my laptop

Don’t worry about the debug version. So to use PyROOT, first, open a x86 Native Tools Command Prompt for VS 2022, and type cd %USERPROFILE%. Then, type C:\root\bin\thisroot.bat (if you installed ROOT in C:\root, otherwise change the location accordingly. Then, you can start Python, and from the Python prompt you can import ROOT. You should have something like:

**********************************************************************
** Visual Studio 2022 Developer Command Prompt v17.5.1
** Copyright (c) 2022 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

C:\Users\bellenot>C:\root\bin\thisroot.bat

C:\Users\bellenot>python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import ROOT
>>>

Note that you might have to use the same version of Python (3.8 IIRC)

That’s weird. What is the error you get?

got the exe to run. Put the “run anyway” behind a tiny “more info” button

I don’t understand… But anyway, use any version of ROOT which is working for you, and follow the instructions I gave previously

please read carefully, I wrote
cd %USERPROFILE%

so it seems root hasnt been built for 3.10 yet


So i followed instructions. redownloaded python as 3.8, still wont support

If you have 32 bit ROOT, you must install 32 bit Python, or use 64 bit Python and install 64 bit ROOT. Everything (not only ROOT and not only on Windows) must be of the same architecture

wait my python is 64 bit?

Yes, just look at the screenshot you posted

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.