Reputation: 61
I am attempting to use a python file in a basic web application. I have my two requirements (docx and xlrd) in my requirements.txt file, but when the python file tries to import either of the requirements, it cannot find the module. I am currently working on Repl.it. Pictures are attached.
I have tried to import only in either location, but I either fail to import the necessary packages, or I cannot refer to functions from the necessary file.
Requirements.txt -
xlrd==1.2.0
docx==0.2.4
other
script.py -
import docx
from docx.enum.table import WD_ALIGN_VERTICAL
import xlrd
error -
(continued)
File "<frozen importlib._bootstrap>", line 978, in _gcd_import
File "<frozen importlib._bootstrap>", line 961, in _find_and_load
File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 655, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed
File "/home/runner/main/urls.py", line 5, in <module>
from main import views
File "/home/runner/main/views.py", line 3, in <module>
from excelToDocx import transfer
File "/home/runner/excelToDocx.py", line 1, in <module>
import xlrd
ModuleNotFoundError: No module named 'xlrd'
exit status 1
Upvotes: 6
Views: 13020
Reputation: 1005
You need to install the packages using the command pip install -r requirements.txt
. If they aren't installed, it isn't going to find them.
The requirements.txt
file is simply a way to tell users of your package what requirements there are for your program, and then let them install all of them easily through PyPi using the pip
program. It doesn't actually tell python to install them for you.
Upvotes: 9