ModuleNotFoundError: No module named 'requests'

Hi,

I am porting* an application to extract Service Metrics from a cloud based bug and issue tracking app called SIFTER.

It provides some Python to help digest the JSON data that it provides through its API. (accounts.py)

This uses the requests package which I have added to the project along with python-dateutil.

However, when ever I try to run the project it gives the error:

ModuleNotFoundError: No module named 'requests'

When I add the requests (and python-dateutil) I get this after it sets the status to built:

Assembling config...Done
Loading base image...Done
Installing custom packages...
Requirement already satisfied: requests in ./.env/lib/python3.10/site-packages (from -r /home/anvil/custom-requirements.txt (line 1)) (2.31.0)
Collecting python-dateutil (from -r /home/anvil/custom-requirements.txt (line 2))
  Downloading python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 247.7/247.7 kB 16.1 MB/s eta 0:00:00
Requirement already satisfied: charset-normalizer<4,>=2 in ./.env/lib/python3.10/site-packages (from requests->-r /home/anvil/custom-requirements.txt (line 1)) (3.1.0)
Requirement already satisfied: idna<4,>=2.5 in ./.env/lib/python3.10/site-packages (from requests->-r /home/anvil/custom-requirements.txt (line 1)) (3.4)
Requirement already satisfied: urllib3<3,>=1.21.1 in ./.env/lib/python3.10/site-packages (from requests->-r /home/anvil/custom-requirements.txt (line 1)) (2.0.3)
Requirement already satisfied: certifi>=2017.4.17 in ./.env/lib/python3.10/site-packages (from requests->-r /home/anvil/custom-requirements.txt (line 1)) (2023.5.7)
Requirement already satisfied: six>=1.5 in ./.env/lib/python3.10/site-packages (from python-dateutil->-r /home/anvil/custom-requirements.txt (line 2)) (1.14.0)
Installing collected packages: python-dateutil
Successfully installed python-dateutil-2.8.2
Saving image...Done

Note: It did create a red button for Security issues in some packages - but this has disappeared.

Does anyone know what I have done wrong?

I think that I could substitute the anvil.http package instead (I am new to python so I am never sure) but I wanted to understand why this is happening.

My apologies if my searches did not find a pre-existing answer for this.

Thanks

Adrian

  • From Actian OpenROAD
    I am splitting this effort between the Anvil IDE and MS Code on Windows 10 with a local anvil server installed. Being new to python I really need a debugger to help me bridge the syntax and understand the return types from calls etc. But in the Windows version I can’t work out how to resolve the issue “Import “._anvil_designer” could not be resolved” or how to install these dependant packages into the Anvil virtual directory (is that what its called?)

I think I just spotted a big clue:

`ModuleNotFoundError: No module named 'requests'`

To make HTTP requests from client code, use the anvil.http module.

* `at RSAKPI, line 3`

Use of the requests package is barred?

fwiw it never was before, i’m going to test on a new app for you now.

Also welcome to the forums :wave:

Do you mind posting what packages you are trying to install, (one includes requests as a requirement apparently) and the base package you are starting from?

One moment, I realised that I was using the wrong date package - I wanted dateutils and not python-dateutil.

It’s building.

1 Like

I am having a few python related issues with the dateutil.parser code that I stole from the internet.

I have a ‘import dateutil.parser’ line and I am just trying to remember where exactly I got that.

Current candidate is back to python_dateutil.

I started down the route to use anvil.http and hit the dateutil issue.

Mmm.

When I run the app with teh python_dateutil added I also get:

ModuleNotFoundError: No module named 'dateutil'
Not all modules are available in client code. Click for more info  

    at RSAKPI, line 7

I must have done something daft to break it this good.

The client side docs might help explain this

Ah.

Are you nudging me towards the notion it might be a restriction in the client side environment?

So I should put all the clever pythony stuff in the server?

1 Like

Hello,

I move all the crunchy bits server side, and I was reminded why I took it all client side a few weeks ago.

Call takes too long to execute.

I’ll pull it onto my Windows host to get it running fully. (I did not know how to execute it locally at the time)

Thanks.

Adrian

Yes, this is the normal way to use packages, the client browser uses skulpt which is a python to javascript transpiler.

See:

and

If your calls take longer than 30 seconds, you can look into background tasks, or using anvil-uplink, but it looks like you already figured that out. :slightly_smiling_face: