# How executing python file?

**URL:** <https://community.jenkins.io/t/how-executing-python-file/6660>\
**Category:** Ask a question\
**Tags:** question\
**Created:** [April 3, 2023, 8:33pm UTC](https://community.jenkins.io/t/how-executing-python-file/6660 "2023-04-03T20:33:29Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![raul-parada](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/raul-parada/32/3828_2.png) [@raul-parada](https://community.jenkins.io/u/raul-parada)\
**Post date:** [April 3, 2023, 8:33pm UTC](https://community.jenkins.io/t/how-executing-python-file/6660/1 "2023-04-03T20:33:29Z")

</div>

Hi,

I’m new using Jenkins. My goal is to run a unitest python file on Jenkins. My environment is Windows 10 with a Jenkins version 2.387.1. I’ve installed the default plugins and the additional python. The python file was created in Anaconda (Spyder) with a version of python 3.9.

The python code is the following:

```auto
from selenium import webdriver
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import unittest

class TestURLs(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))

    def tearDown(self):
        self.driver.quit()

    def test_multiple_urls(self):
        urls = [
            "https://www.wikipedia.org/",
            "https://www.google.com/",
            "https://www.github.com/"
        ]

        for url in urls:
            # Navigate to the URL
            self.driver.get(url)
            wait = WebDriverWait(self.driver, 10)
           
            
if __name__ == ' __main__':
    unittest.main()

```

I’ve created a Freestyle Project with a Build Steps as Execute Shell with the following commands:

```auto
cd\
python -m unittest C:\Users\user\multicooki.py

```

When I Build Now the project, I do not get any response. What I’m missing?  
Thank in advanced.

---

<div class="post-metadata">

**Author:** ![slide\_o\_mix](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/slide_o_mix/32/20977_2.png) [@slide\_o\_mix](https://community.jenkins.io/u/slide_o_mix)\
**Post date:** [April 3, 2023, 10:13pm UTC](https://community.jenkins.io/t/how-executing-python-file/6660/2 "2023-04-03T22:13:08Z")

</div>

When you say you don’t get any response, what do you mean by that? What are you trying to do with the `cd\` that you have in your job?

---

<div class="post-metadata">

**Author:** ![raul-parada](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/raul-parada/32/3828_2.png) [@raul-parada](https://community.jenkins.io/u/raul-parada)\
**Post date:** [April 3, 2023, 10:40pm UTC](https://community.jenkins.io/t/how-executing-python-file/6660/3 "2023-04-03T22:40:55Z")

</div>

By no response, I meant there is not output. The cd\ is to go to the root of the path. More details about my code is that the python file is executed within an anaconda virtual environment. I don’t know if this affects the procedure. I stack on how to configure the project to setup a job capable of executing a python file.

---

<div class="post-metadata">

**Author:** ![raul-parada](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/raul-parada/32/3828_2.png) [@raul-parada](https://community.jenkins.io/u/raul-parada)\
**Post date:** [April 3, 2023, 11:07pm UTC](https://community.jenkins.io/t/how-executing-python-file/6660/4 "2023-04-03T23:07:45Z")

</div>

I’ve installed the appropriate libraries to make it run outside the virtual environment and following this steps on cmd I could make it work, however, I put the same commands inside the execute shell

```auto
cd\
cd C:\Users\user\
py -m multicooki

```

and by clicking Build Now, it remains here  
 ![image](https://europe1.discourse-cdn.com/flex013/uploads/jenkins/original/2X/1/11449cab74fdaf9acedfe28a534874b138321af6.png)

---

<div class="post-metadata">

**Author:** ![halkeye](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/halkeye/32/8_2.png) [@halkeye](https://community.jenkins.io/u/halkeye)\
**Post date:** [April 4, 2023, 5:53am UTC](https://community.jenkins.io/t/how-executing-python-file/6660/5 "2023-04-04T05:53:28Z")

</div>

> [@raul-parada](#):
>
> By no response, I meant there is not output.

your script has no output, no prints or anything.

also can you share your pipeline?

---

<div class="post-metadata">

**Author:** ![raul-parada](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/raul-parada/32/3828_2.png) [@raul-parada](https://community.jenkins.io/u/raul-parada)\
**Post date:** [April 4, 2023, 6:54am UTC](https://community.jenkins.io/t/how-executing-python-file/6660/6 "2023-04-04T06:54:41Z")

</div>

Well, this script has not print, however, the one executed does. About the pipeline, I didn’t configured one? it should be linked to the created project? How should I configured it? Apologies for too much questions.

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [April 4, 2023, 6:56am UTC](https://community.jenkins.io/t/how-executing-python-file/6660/7 "2023-04-04T06:56:02Z")

</div>

You wrote you’re on windows but then you mentioned to use “execute shell”. Shell will only work on Unix, in a Freestyle project you need to use “execute windows batch”.

You posted a picture where one can see that you might have a misconfiguration in your job. You assigned a label where to execute the job but there is no agent available that has this label. So the job will never start.

---

<div class="post-metadata">

**Author:** ![raul-parada](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/raul-parada/32/3828_2.png) [@raul-parada](https://community.jenkins.io/u/raul-parada)\
**Post date:** [April 4, 2023, 7:13am UTC](https://community.jenkins.io/t/how-executing-python-file/6660/8 "2023-04-04T07:13:26Z")

</div>

@mawinter69 I’ve changed shell to batch and I’ve created an agent with the project name. I could executed it, however, I get this console output:

`Started by user [rparada](http://localhost:8080/user/rparada) Running as SYSTEM Building in workspace C:\ProgramData\Jenkins\.jenkins\workspace\pythonCookies [pythonCookies] $ cmd /c call C:\Windows\TEMP\jenkins3692175436805402094.bat C:\ProgramData\Jenkins\.jenkins\workspace\pythonCookies>cd\ C:\>cd C:\Users\user\ C:\Users\user>py -m multicooki No installed Python found! C:\Users\user>exit 112 Build step 'Execute Windows batch command' marked build as failure Finished: FAILURE`

I have installed all possible python plugins (with restart). The code works locally following the same steps. Why it says No installed Python found?

Thanks

---

<div class="post-metadata">

**Author:** ![mawinter69](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/mawinter69/32/1625_2.png) [@mawinter69](https://community.jenkins.io/u/mawinter69)\
**Post date:** [April 4, 2023, 7:48am UTC](https://community.jenkins.io/t/how-executing-python-file/6660/9 "2023-04-04T07:48:35Z")

</div>

hard to tell why it is not found.  
When you installed python did you install it as administrator making it available for all users? If not are you running your agent with the same user account used to install python?

---

<div class="post-metadata">

**Author:** ![raul-parada](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/raul-parada/32/3828_2.png) [@raul-parada](https://community.jenkins.io/u/raul-parada)\
**Post date:** [April 4, 2023, 10:50am UTC](https://community.jenkins.io/t/how-executing-python-file/6660/10 "2023-04-04T10:50:12Z")

</div>

I was wrong, I didn’t configure an agent it was the in-built node. I’ve seen different ways to configure the agent. Please, could you recommend me a link? I’ve seen this procedure [How to Install Jenkins Agent on Windows - YouTube](https://www.youtube.com/watch?v=N8AQTlHoBKc)
