Difference between revisions of "Virtual environment on Windows"

From Kraken Wiki
Jump to: navigation, search
(Virtual environment)
(Adding folders to the Python path)
 
(9 intermediate revisions by the same user not shown)
Line 3: Line 3:
 
Also choose "Disable path length limit" if prompted.
 
Also choose "Disable path length limit" if prompted.
  
==Check==
+
==== Check Python path ====
  
Open a command propmt and run
+
Open a command prompt and run
  
 
  python
 
  python
Line 14: Line 14:
 
and make sure that the location of the Python executable is the same you noted down during the installation.
 
and make sure that the location of the Python executable is the same you noted down during the installation.
  
==Virtual environment==
+
==== Installing and using the virtual environment====
  
 
Open a command prompt and run
 
Open a command prompt and run
Line 37: Line 37:
  
 
to see, where the virtual environments are stored.
 
to see, where the virtual environments are stored.
 +
 +
The batch file
 +
 +
%WORKON_HOME%\kraken\Scripts\activate.bat
 +
 +
can be edited to add new environment variables at its end:
 +
 +
 +
set "TRACEP5_EXE_PATH=C:\TRACE-V50P5-Exe\Executables\trace-V50p5-windows-msvs2017-ivf-x86-Release.exe"
 +
etc.
 +
 +
 +
==== Installing dependencies ====
 +
 +
Dependencies can be installed using
 +
pip install --upgrade numpy
 +
pip install --upgrade scipy
 +
pip install --upgrade matplotlib
 +
pip install --upgrade serpenttools
 +
in the kraken environment.
 +
 +
==== Adding folders to the Python path ====
 +
 +
In Windows 10, open
 +
Control Panel\All Control Panel Items\User Accounts
 +
open
 +
Change my environment variables
 +
on the left sidebar, and use
 +
New...
 +
below the
 +
User variables for <my_username>
 +
to add the environment variables for the different solvers. For example, specify
 +
ANTS_EXE_PATH
 +
in the
 +
Variable name:
 +
field and for example
 +
C:\data\src\Ants\vs2015\x64\Debug\Ants.exe
 +
in the
 +
Variable value:
 +
field. Note that if you want to use either debug or release version of the different executables, the paths have to be changed.
 +
 +
Create or add to PYTHONPATH environment variable
 +
C:\data\src\Cerberus
 +
C:\data\src\KrakenTools
 +
or similar depending on the install location (use ; to separate paths if needed), do NOT add
 +
C:\data\src\Cerberus\cereberus
 +
C:\data\src\KrakenTools\krakentools
 +
or similar.
 +
 +
==== VS Code ====
 +
 +
 +
If using Visual Studio Code to run Python, at least in Windows one should finally have
 +
{
 +
    // Use IntelliSense to learn about possible attributes.
 +
    // Hover to view descriptions of existing attributes.
 +
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 +
    "version": "0.2.0",
 +
    "configurations": [
 +
        {
 +
            "name": "Python: Current File",
 +
            "type": "python",
 +
            "request": "launch",
 +
            "program": "${file}",
 +
            "console": "internalConsole"
 +
        },
 +
    ]
 +
}
 +
in
 +
.vscode/launch.json
 +
to launch the Python in correct console. This file may have to be in every folder where Visual Studio Code is launched. Another option is to put in a global settings.json, which can be opened from File->Preferences->Settings->Search for launch and click Edit in settings.json and add the above as
 +
    "launch": {
 +
        // Use IntelliSense to learn about possible attributes.
 +
        // Hover to view descriptions of existing attributes.
 +
        // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
 +
        "version": "0.2.0",
 +
        "configurations": [
 +
            {
 +
                "name": "Python: Current File",
 +
                "type": "python",
 +
                "request": "launch",
 +
                "program": "${file}",
 +
                "console": "internalConsole"
 +
            }
 +
        ]
 +
    }

Latest revision as of 09:53, 30 January 2024

Get Python 3.8 from the Python website (executable installer for Windows). During installation, tick the box for "add Python 3.8 to PATH" and take note of the installation location.

Also choose "Disable path length limit" if prompted.

Check Python path

Open a command prompt and run

python
>>> import sys
>>> print(sys.executable)

and make sure that the location of the Python executable is the same you noted down during the installation.

Installing and using the virtual environment

Open a command prompt and run

python3.8 -m pip install virtualenv
python3.8 -m pip install virtualenvwrapper-win

(Close the command prompt and open a new one.)

mkvirtualenv kraken
python3.8 -m virtualenv kraken

After this the following commands should work

workon kraken
<... do some work in the environment ...>
deactivate

Also see

echo %WORKON_HOME%

to see, where the virtual environments are stored.

The batch file

%WORKON_HOME%\kraken\Scripts\activate.bat

can be edited to add new environment variables at its end:


set "TRACEP5_EXE_PATH=C:\TRACE-V50P5-Exe\Executables\trace-V50p5-windows-msvs2017-ivf-x86-Release.exe"
etc.


Installing dependencies

Dependencies can be installed using

pip install --upgrade numpy
pip install --upgrade scipy
pip install --upgrade matplotlib
pip install --upgrade serpenttools

in the kraken environment.

Adding folders to the Python path

In Windows 10, open

Control Panel\All Control Panel Items\User Accounts

open

Change my environment variables

on the left sidebar, and use

New...

below the

User variables for <my_username>

to add the environment variables for the different solvers. For example, specify

ANTS_EXE_PATH

in the

Variable name:

field and for example

C:\data\src\Ants\vs2015\x64\Debug\Ants.exe

in the

Variable value:

field. Note that if you want to use either debug or release version of the different executables, the paths have to be changed.

Create or add to PYTHONPATH environment variable

C:\data\src\Cerberus
C:\data\src\KrakenTools

or similar depending on the install location (use ; to separate paths if needed), do NOT add

C:\data\src\Cerberus\cereberus
C:\data\src\KrakenTools\krakentools

or similar.

VS Code

If using Visual Studio Code to run Python, at least in Windows one should finally have

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",	
            "console": "internalConsole"
        },
    ]
}

in

.vscode/launch.json

to launch the Python in correct console. This file may have to be in every folder where Visual Studio Code is launched. Another option is to put in a global settings.json, which can be opened from File->Preferences->Settings->Search for launch and click Edit in settings.json and add the above as

   "launch": {
       // Use IntelliSense to learn about possible attributes.
       // Hover to view descriptions of existing attributes.
       // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
       "version": "0.2.0",
       "configurations": [
           {
               "name": "Python: Current File",
               "type": "python",
               "request": "launch",
               "program": "${file}",
               "console": "internalConsole"
           }
       ]
   }