# Python Virtual Environment

**URL:** <https://forum.uipath.com/t/python-virtual-environment/400025>\
**Category:** Studio\
**Tags:** new-feature-request, virtual-environment, question, studio, python, activities\
**Created:** [February 17, 2022, 6:59am UTC](https://forum.uipath.com/t/python-virtual-environment/400025 "2022-02-17T06:59:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Donnas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/donnas/32/287649_2.png) [@Donnas](https://forum.uipath.com/u/Donnas)\
**Post date:** [February 17, 2022, 6:59am UTC](https://forum.uipath.com/t/python-virtual-environment/400025/1 "2022-02-17T06:59:43Z")

</div>

Hi UiPath community,

I have been trying to use a python virtual environment (created in VS code) within the Python Scope Application in Studio, but I get a python engine error. Is it possible to use virtual environments within UiPath, or does Python need to be installed globally?

Adding this feature would help a lot to avoid situations where Python may not be installed on another PC (such as a client’s VM).

---

<div class="post-metadata">

**Author:** ![jeevith](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/jeevith/32/288449_2.png) [@jeevith](https://forum.uipath.com/u/jeevith)\
**Post date:** [February 18, 2022, 8:04pm UTC](https://forum.uipath.com/t/python-virtual-environment/400025/2 "2022-02-18T20:04:16Z")

</div>

Hi @Donnas,

I agree that this could be really good to support out of the box. However, if you want to run the python scope from a python installed in a shared drive/VM / USB stick you can look at this workaround here :

Via a shared drive : [Python integration with different vm's - #7 by jeevith](https://forum.uipath.com/t/python-integration-with-different-vms/386337/7)

Via a USB : [How to run python script in UiPath without installing python? - #4 by jeevith](https://forum.uipath.com/t/how-to-run-python-script-in-uipath-without-installing-python/271827/4)

The point being, UiPath’s invoke python scope does not care where python is installed but it wants to see a full installation python in the folder path provided in the activity.

Since the folder structure of a virtual env is not similar to a standard install of python, it fails. If you use the python.exe from “env/Scripts/” (as the python installation folder being parsed by UiPath does not support the virtualenv folder structure).

For people who are wondering what the error message we get:  
 ![image](https://global.discourse-cdn.com/uipath/original/4X/5/5/a/55afec579b065e2e84ee814797a28790e44246c4.png)

**In this case there is an alternative:**

Another approach is to skip Python Scope activity and rather use ever versatile Invoke PowerShell activity.

1. cd to your working folder path where you have the virtual environment
2. Activate the virtualenv from PowerShell
3. Run python “pythonfile.py”
4. In the Invoke PowerShell activity, return the output as PSOutput (as the datatype required)

 ![image](https://global.discourse-cdn.com/uipath/original/4X/0/3/4/034ca39efcfe87a79416408a09fc98bc35cfad85.png)

**Resources**

```auto
Param(
[Parameter(Mandatory=$true)] [string]$VirtualEnvFolder,
[Parameter(Mandatory=$true)] [string]$PythonFilePath
)
cd $VirtualEnvFolder
env/Scripts/activate.bat
python $PythonFilePath

```

```auto
def runInVirtualEnv():
    return "I just ran on a virtual env!"

print (runInVirtualEnv())

```

[PythonVirtualEnv.xaml](https://forum.uipath.com/uploads/short-url/78XZCyhebgqlR4C2W7v291TEZ2Y.xaml) (8.8 KB)

**Why not use the default activate.ps1 to activate?**  
I use the default `.bat` file to activate the virtualenv. You can use `activate.ps1` if you wish, but in my experience `.ps1` scripts usually require higher user access with a set execution policy `Set-ExecutionPolicy Unrestricted` . It is done for security, but when activating virtualenv `.bat` file will work without errors.

Hope this helps you and others.

---

<div class="post-metadata">

**Author:** ![Donnas](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/donnas/32/287649_2.png) [@Donnas](https://forum.uipath.com/u/Donnas)\
**Post date:** [February 24, 2022, 9:32am UTC](https://forum.uipath.com/t/python-virtual-environment/400025/3 "2022-02-24T09:32:38Z")

</div>

Thanks for your reply, I will have a look at what you have suggested!

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/uipath/user_avatar/forum.uipath.com/system/32/182466_2.png) [@system](https://forum.uipath.com/u/system)\
**Post date:** [November 7, 2022, 7:06am UTC](https://forum.uipath.com/t/python-virtual-environment/400025/4 "2022-11-07T07:06:34Z")

</div>

Closed on November 7, 2022, 7:06am UTC

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