I was running a script today just fine with a dateutil
import:
import os
import re
import json
from dateutil import parser
but now when I try to run the same script I get:
ModuleNotFoundError: No module named 'dateutil'
I have python-dateutil
installed though the package manager (and also tried a pip install when trying to fix this problem) but no luck.
Try using the Packages tool, or poetry add python-dateutil
command in shell, to install the package.
If there are still errors, then type echo $PYTHONPATH
in the shell, and post the output.
Thanks! Updating via poetry didn’t fix it. Here’s my python path
/nix/store/i9nlh2ji8l5nlz3jpl1i6y6p5kqdpwia-nix-update-0.17.2/lib/python3.11/site-packages:/nix/store/pa7ad0v5hs8amap6j09dh72cwc36l0sv-python3-3.11.3/lib/python3.11/site-packages
Try adding $REPL_HOME/.pythonlibs/lib/python3.11/site-packages:
to the begining your PYTHONPATH
variable.
You can just add this to the .replit
file:
[env]
PYTHONPATH = "$REPL_HOME/.pythonlibs/lib/python3.11/site-packages:$PYTHONPATH"
It is a common issue that the path to the repl’s packages is not present in PYTHONPATH
. It may be caused by using pip
, but I am not sure.
So, you should add the code snippet provided above, but put python3.10
instead of python3.11
if your repl uses python 3.10.
Also, put the snippet near the bottom of the .replit
file. You may need to show hidden files first to see the file.
It uses 3.11, I’m pretty sure:
Yeah. It’s a common issue and other users may have python 3.10.
(maybe make a topic or canned reply for this?)
I thought it was
[env]
PYTHONPATH = "${HOME}/${REPL_SLUG}/.pythonlibs/lib/python3.10/site-packages:${PYTHONPATH}"
The bandaid solution is to explicitly add the path in the configuration.
Show hidden files, open .replit file and add this anywhere near the bottom (if the [env] section already exists, just add the variable):
[env]
PYTHONPATH = "${HOME}/${REPL_SLUG}/.pythonlibs/lib/python3.10/site-packages:${PYTHONPATH}"
Refresh. Now, packages should be correctly imported.
Possibly related PYTHONPATH problem topics (cause still unknown):
Pytorch on replit
Error installing dependencies
ModuleNotFoundError…
They are both valid (I forgot about REPL_HOME
when making that one). Generally, "$HOME/$REPL_SLUG"
== "$REPL_HOME"
.
The more important question is whether to add the path to the end or beginning of PYTHONPATH
.
3 Likes
thanks everyone! can confirm that adding:
[env]
PYTHONPATH = "${HOME}/${REPL_SLUG}/.pythonlibs/lib/python3.10/site-packages:${PYTHONPATH}"
to the .replit file did the trick!
1 Like
Hi @brandburner !
Since your problem is solved, please mark the post that helped you most as the Solution.
Thanks!
1 Like
system
Closed
December 20, 2023, 12:36pm
12
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.