" ModuleNotFoundError: No module named 'jose' " ; but it's already installed

1.4k Views Asked by At
Process SpawnProcess-9:
Traceback (most recent call last):
  File "C:\Users\gveda\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 314, in _bootstrap
    self.run()
  File "C:\Users\gveda\AppData\Local\Programs\Python\Python310\lib\multiprocessing\process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\gveda\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\_subprocess.py", line 76, in subprocess_started
    target(sockets=sockets)
  File "C:\Users\gveda\AppData\Local\Programs\Python\Python310\lib\site-packages\uvicorn\server.py", line 60, in run
    return asyncio.run(self.serve(sockets=sockets))
  File "C:\Users\gveda\AppData\Local\Programs\Python\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Users\gveda\AppData\Local\Programs\Python\Python310\lib\asyncio\base_events.py", line 649, in run_until_complete
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed  
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "D:\Programs\FastAPI\.\Blog\main.py", line 4, in <module>    from .routers import blog,user,auth
  File "D:\Programs\FastAPI\.\Blog\routers\auth.py", line 3, in <module>         from .. import schemas,database,models,token
  File "D:\Programs\FastAPI\.\Blog\token.py", line 2, in <module>
    from jose import JWTError, jwt
ModuleNotFoundError: No module named 'jose'

I have already installed python-jose module still it is giving me the error that there is module named jose. From jose module I am importing jwt and there is no module of it. Why ??

I already installed python-jose and jose modules separately still the same error occurs.

1

There are 1 best solutions below

2
On

this is a common mistake and it all stems from environment variables. The problem is that when you write pip in you command line, it points to a path to a certain pip.exe that could be python/3.9/lib/pip.exe python/3.11/lib/pip.exe, python/3.x/lib/pip.exe or any other version of python installed on your machine. So it's likely you installed your lib with a different pip then the one linked to the python executable you are calling your script with.

So either you change your environment variables to something like pip39 and pip311 or you call the specific pip like so:

Windows

C:\WINDOWS\system32>where python
C:\Python311\python.exe
C:\Users\usr\AppData\Local\Programs\Python\Python38-32\python.exe
C:\Users\usr\AppData\Local\Microsoft\WindowsApps\python.exe

Thanks to where we are able to find all instances of python on our machine.

Then all you need to do is call pip like so:

C:\WINDOWS\system32>C:\Python311\python.exe -m pip install my_desired_lib

Now when you call your script you should specify which executable you want to use.

C:\WINDOWS\system32>C:\Python311\python.exe my_script.py

Linux

For the where function use whereis. Apart from that using python is the same, so calling a specific pip and running your script with a specific python.exe is the same.

I hope this will help someone!