# Running Python with n8n

**URL:** <https://community.n8n.io/t/running-python-with-n8n/5715>\
**Category:** Questions\
**Tags:** core, community-node\
**Created:** [May 11, 2021, 3:56pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715 "2021-05-11T15:56:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximpoulsen](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/maximpoulsen/32/11580_2.png) [@maximpoulsen](https://community.n8n.io/u/maximpoulsen)\
**Post date:** [May 11, 2021, 3:56pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/1 "2021-05-11T15:56:22Z")

</div>

Hi n8n community,

We have some Python files that we would like to run on a regular basis, and I was thinking of using n8n for this: A _Cron_ node followed by an _Execute command_ node to run a specific Python file.

Is this possible, and if so does anyone have any insights that could help us deploy such a solution? We have deployed n8n on Heroku, maybe there are some specifics? Such as how to install Python and all necessary libraries.

Also, once we have the Python file that we have developed locally, should we use an FTP to send it to our n8n database or can this be done directly via n8n?

Many thanks,  
Maxim

---

<div class="post-metadata">

**Author:** ![dali](https://avatars.discourse-cdn.com/v4/letter/d/c68b51/32.png) [@dali](https://community.n8n.io/u/dali)\
**Post date:** [May 11, 2021, 5:30pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/2 "2021-05-11T17:30:29Z")

</div>

Hi @maximpoulsen , that’s totally doable as you can see in the screenshot. Basically the _execute command_ node is a bash instance where you can execute any available command.

To achieve what you are aiming for, you need to have python installed on your instance with the required libraries you will be using.  
Also you can use the _execute command_ node to install them, just make sure you have the right user (with the right privileges) when starting then n8n instance.

Concerning the files, it is better to save them directly on the file system, rather than using n8n database, also you can use a combination of _FTP_ and _writeBinaryFile_ node to retrieve and save the files before executing them.

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/f/f0ce3dd0015dc9f571a6e1aac14da635bc4538fe.png)

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [May 11, 2021, 6:19pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/3 "2021-05-11T18:19:27Z")

</div>

Btw. if you want to build a docker-image with python you can extend the default n8n image and extend it.

For that create a file name `Dockerfile` with this content:

```bash
FROM n8nio/n8n
RUN apk add --update python3 py3-pip

```

And then run in the same folder the following command to build it:

```bash
docker build -t n8n-python .

```

If you then use this image, you will be able to run python scripts (be aware that you would have to use the command `python3` and not `python`).

---

<div class="post-metadata">

**Author:** ![chris](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/chris/32/1250_2.png) [@chris](https://community.n8n.io/u/chris)\
**Post date:** [May 12, 2021, 5:35pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/4 "2021-05-12T17:35:50Z")

</div>

Thanks @jan,  
Is it also possible to add python to a docker-compose file? I use docker-compose to deploy n8n and traefik but would love to add python support as well.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [May 12, 2021, 7:00pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/5 "2021-05-12T19:00:08Z")

</div>

Yes, @chris! The docker-compose file just describes how what docker images to use and with what parameters. So you would do exactly what I did explain above and then change the docker-image you use in the docker-compose file.

So from something like:

```nohighlight
...
  n8n:
    image: n8nio/n8n
...

```

to:

```nohighlight
...
  n8n:
    image: n8n-python
...

```

---

<div class="post-metadata">

**Author:** ![chris](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/chris/32/1250_2.png) [@chris](https://community.n8n.io/u/chris)\
**Post date:** [May 12, 2021, 7:14pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/6 "2021-05-12T19:14:47Z")

</div>

Thanks @jan.

To understand completely:  
`image: n8nio/n8n` uses official n8n image from the docker registry, while  
`image: n8n-python` uses the image I locally build (which uses official `n8nio/n8n`, just with python)?

I know this is a Docker specific question, so appreciate your support here.

---

<div class="post-metadata">

**Author:** ![jan](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jan/32/9_2.png) [@jan](https://community.n8n.io/u/jan)\
**Post date:** [May 12, 2021, 7:32pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/7 "2021-05-12T19:32:29Z")

</div>

Yes, that is 100% correct.

It is however important to remember that you would have to build a new custom image every time a new n8n version gets released.

So would be best to use a Dockerfile like this:

```bash
FROM n8nio/n8n:0.119.0
RUN apk add --update python3 py3-pip

```

in which you specify the exact version of the n8n image you want to use. After that has then be build you would have to do:

```bash
# Stop the currently running containers
docker-compose stop 
# Remove them so that it has to recreate them and does not reuse the old ones
docker-compose rm
# Startup n8n again
docker-compose up -d

```

---

<div class="post-metadata">

**Author:** ![d4vidsha](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/d4vidsha/32/24617_2.png) [@d4vidsha](https://community.n8n.io/u/d4vidsha)\
**Post date:** [January 12, 2022, 8:38pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/8 "2022-01-12T20:38:27Z")

</div>

> [@jan](#):
>
> Btw. if you want to build a docker-image with python you can extend the default n8n image and extend it.
> 
> For that create a file name `Dockerfile` with this content:
> 
> ```auto
> FROM n8nio/n8n
> RUN apk add --update python3 py3-pip
> 
> ```
> 
> And then run in the same folder the following command to build it:
> 
> ```auto
> docker build -t n8n-python .
> 
> ```
> 
> If you then use this image, you will be able to run python scripts (be aware that you would have to use the command `python3` and not `python`).

Is there a way to add external libraries permanently? Every time I restart my docker container, the requests library gets lost and I’m greeted with this error.

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/d/de8ec15d9896cdff5dce152a2703598b034e22fe.png)

After I successfully install the library again with `pip3 install requests` in an execute command node, I get the following warning,

```auto
WARNING: The script normalizer is installed in '/home/node/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: You are using pip version 21.1.1; however, version 21.3.1 is available. You should consider upgrading via the '/usr/bin/python3.8 -m pip install --upgrade pip' command.

```

 ![image](https://europe1.discourse-cdn.com/n8n/original/2X/b/b4136b95ad2ed79594e2a034046b8a9b4528aeaa.png)

I think they are related? So how do I fix this? Thanks 🙂

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 12, 2022, 8:47pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/9 "2022-01-12T20:47:26Z")

</div>

Hey @d4vidsha,

You may need to make a storage volume to store the Python modules and map it to the module path on the container, that should then make them available.

I have not tested it though so it is just theory.

---

<div class="post-metadata">

**Author:** ![d4vidsha](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/d4vidsha/32/24617_2.png) [@d4vidsha](https://community.n8n.io/u/d4vidsha)\
**Post date:** [January 12, 2022, 9:32pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/10 "2022-01-12T21:32:07Z")

</div>

I think so too @jon. I’m not sure how to do this though.

---

<div class="post-metadata">

**Author:** ![Jon](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/jon/32/40174_2.png) [@Jon](https://community.n8n.io/u/Jon)\
**Post date:** [January 13, 2022, 6:11am UTC](https://community.n8n.io/t/running-python-with-n8n/5715/11 "2022-01-13T06:11:20Z")

</div>

Have you throught about using a requirements file that you load in your docker file to install the modules needed when the container is built? Could be easier and more familiar if you know your way around Python.

---

<div class="post-metadata">

**Author:** ![kgurinov](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/kgurinov/32/18409_2.png) [@kgurinov](https://community.n8n.io/u/kgurinov)\
**Post date:** [July 30, 2022, 6:56pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/12 "2022-07-30T18:56:25Z")

</div>

Is there an update on how to install the python image and have libraries stored?

---

<div class="post-metadata">

**Author:** ![kgurinov](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/kgurinov/32/18409_2.png) [@kgurinov](https://community.n8n.io/u/kgurinov)\
**Post date:** [July 30, 2022, 8:07pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/13 "2022-07-30T20:07:35Z")

</div>

> [@d4vidsha](#):
>
> pip3 install requests

How could i do that? create a storage or folder i got but where you make them available?

---

<div class="post-metadata">

**Author:** ![d4vidsha](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/d4vidsha/32/24617_2.png) [@d4vidsha](https://community.n8n.io/u/d4vidsha)\
**Post date:** [July 30, 2022, 9:31pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/14 "2022-07-30T21:31:14Z")

</div>

I explain my process in full here: [How to automatically update n8n-python](https://davidsha.me/how-to-automatically-update-n8n-python/)

If there’s anything in this which doesn’t make sense, hit me up 😄

---

<div class="post-metadata">

**Author:** ![kgurinov](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/kgurinov/32/18409_2.png) [@kgurinov](https://community.n8n.io/u/kgurinov)\
**Post date:** [August 3, 2022, 7:36pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/16 "2022-08-03T19:36:34Z")

</div>

Thats cool info, will work on it.

By the way do you know on how to install Anaconda?

---

<div class="post-metadata">

**Author:** ![kayjey](https://avatars.discourse-cdn.com/v4/letter/k/ecd19e/32.png) [@kayjey](https://community.n8n.io/u/kayjey)\
**Post date:** [November 15, 2022, 1:35pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/17 "2022-11-15T13:35:17Z")

</div>

Is there a way to get some custom data from previous node and give that as a input to this python node, to transform the data and then later output it to other node ?  
I cant find any node in n8n that would support advanced data transformation , like pandas , or once the data is fetched from diff source, no sql like query option to transform that data to my liking.  
I was thinking if i can do this in python

---

<div class="post-metadata">

**Author:** ![Leonardo\_Alcantara](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/leonardo_alcantara/32/19451_2.png) [@Leonardo\_Alcantara](https://community.n8n.io/u/Leonardo_Alcantara)\
**Post date:** [November 22, 2022, 1:35pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/18 "2022-11-22T13:35:25Z")

</div>

Hello Jan, can you help me?

The DockerFile i can create anywhere? Or it already exists?  
I pretty new with Docker and a little confused 😅

---

<div class="post-metadata">

**Author:** ![d4vidsha](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/d4vidsha/32/24617_2.png) [@d4vidsha](https://community.n8n.io/u/d4vidsha)\
**Post date:** [January 10, 2023, 5:05am UTC](https://community.n8n.io/t/running-python-with-n8n/5715/19 "2023-01-10T05:05:01Z")

</div>

Old link now does not work, here is the [new link](https://blog.davidsha.me/how-to-automatically-update-n8n-python/).

---

<div class="post-metadata">

**Author:** ![Imperol](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/imperol/32/40883_2.png) [@Imperol](https://community.n8n.io/u/Imperol)\
**Post date:** [January 3, 2024, 9:09pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/20 "2024-01-03T21:09:23Z")

</div>

How about when running it on the npm global. I have been having an error

“ERROR: exitCode: 1 Traceback (most recent call last): File “C:\Users\user\AppData\Local\Temp\36107e071cc1c15332690c0d325e0c13.py”, line 1, in import fire ModuleNotFoundError: No module named ‘fire’” yet I have al modules installed

---

<div class="post-metadata">

**Author:** ![Chase\_Woodhams](https://dub1.discourse-cdn.com/n8n/user_avatar/community.n8n.io/chase_woodhams/32/39553_2.png) [@Chase\_Woodhams](https://community.n8n.io/u/Chase_Woodhams)\
**Post date:** [May 20, 2024, 5:42pm UTC](https://community.n8n.io/t/running-python-with-n8n/5715/21 "2024-05-20T17:42:18Z")

</div>

I am looking over your guide, and Im a little confused.

I am looking to use the latest n8n Image with advanced AI nodes and I also need to run a python library that requires 3.11 but all I can seem to find premade are 3.10.

How do you specify the version of python? Would it be easier to just update python in an existing image?

Like this: [Docker](https://hub.docker.com/r/naskio/n8n-python)

Looking forward to getting this project rolling. Thank you!

[Next page](https://community.n8n.io/t/running-python-with-n8n/5715.md?page=2)
