I'm in battle with one error sine yesterday. I checked similar topics on stackoverflow, but nothing worked.
That's my project structure:
When I type:
uvicorn main:app --reload
To start fastapi this error occure:
File ".\main.py", line 2, in
from scraper.scraper import Scraper
File ".\scraper\scraper.py", line 3, in
import pandas as pd
ModuleNotFoundError: No module named 'pandas'
I have tried to add new PATH in windows, change structure of my project. Do you know hot to handle it?
Not pycharm problem,
when running in pycharm terminal your python runs in venv - which has seperate pip packages (thats the point of venv), but uvicorn probably passes the data to local python installation and not the venv.
so now after installing pandas in regular cmd, its installed system wide, and you can try running your command in pycharm too
Related
Can I access the class inside the multiple folder of one script file in python I did that and when I start running the scripts it is working fine here(import like this from tosca_o.service.service_model.service_model_service import ServiceModelService) in eclipse, but when I start run in the ubuntu terminal I m facing some issues the issue is below.
Issue
ImportError while loading conftest '/home/naga/workarea/tosca-o/zyuvnag/tosca-o/core/rest/src/tosca_o/rest/tests/conftest.py'.
conftest.py:4: in
from tosca_o.service.service_model.service_model_service import ServiceModelService
E ModuleNotFoundError: No module named 'tosca_o'
Could please help me to resolve this issue.
Thanks for your support.
when I start running the scripts it is working fine here(import like this from tosca_o.service.service_model.service_model_service import ServiceModelService)in the eclipse.
but when I start run in the ubuntu terminal I m facing some issues the issue is below.
Issue
ImportError while loading conftest '/home/naga/workarea/tosca-o/zyuvnag/tosca-o/core/rest/src/tosca_o/rest/tests/conftest.py'.
conftest.py:4: in
from tosca_o.service.service_model.service_model_service import ServiceModelService
E ModuleNotFoundError: No module named 'tosca_o'
I followed the instructions and successfully installed pypostal python package (package to help parse addresses) https://github.com/openvenues/pypostal.
I'm trying to set this up so the python script can be callable through an apache server on an ubuntu box. It works fine when executing the script from Terminal. However, it doesn't work when I make a call to apache to execute the script and I get the following error in the apache logs. I believe it might be some pathing issue but I haven't had much luck to resolve it. Any ideas will be appreciated.
Error:
File "/var/www/html/cgi-bin/get_parsedAddress.py", line 5, in
from postal.parser import parse_address
ModuleNotFoundError: No module named 'postal'
python script contents:
import sys
from postal.parser import parse_address
addressList = parse_address(sys.argv[1])
print(addressList)
I have installed Anaconda-Package, Flask, Pip & Vscode. I am currently running the development project on localhost using "pipenv shell" command then "flask run" command in vscode.
It works well on http://127.0.0.1:5000/ for simple webapp. But I want to display the prediction charts & tables on a webpage using pandas, numpy etc.
So, When I try to import
import pandas as pd
import numpy as np
It displays this ->
flask.cli.NoAppException
flask.cli.NoAppException: While importing "app", an ImportError was raised:
Traceback (most recent call last):
File "c:\users\mdev\.virtualenvs\flask_md_project-itylmdvv\lib\site-packages\flask\cli.py", line 240, in locate_app
__import__(module_name)
File "D:\flask_md_project\app.py", line 4, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
above error as image
How do I use pandas,numpy,matplotlib etc from anaconda package along with flask through vscode for my python webapp ? Please help 🙏
According to the information you provided, the modules "pandas" and "numpy" are not installed in the Python environment you are currently using.
When we use the conda environment in VS Code, we use it as a python environment. Therefore, in this environment we need to install the module and then use this module. Usually, the module storage location of conda environment is (for example, base conda environment): "\users\username\anaconda3\lib\site-packages".
We can use the command "pip show pandas" in the VS Code terminal to check the installation location of the module:
For more information about flask in VS Code, you could refer to: Flask Tutorial in Visual Studio Code.
Install numpy on anaconda by running;
conda install numpy
I know there are a lot of similar questions to this but I have tried all the solutions I could find and none of them seem to work.
I have a python script that I run every day through task scheduler (Windows 10) that includes the lines
import pandas as pd
import numpy as np
For about 2 weeks this script ran on schedule with no problems and then stopped working (I may have updated something at this point but I can't remember). Specifically, it no longer works when run directly through the console i.e. >python C:\dir\script.py. But it still works fine if I load the script in Spyder and run it there.
The error it throws is the following:
Traceback (most recent call last):
File "script.py", line 15, in <module>
import pandas as pd
File "C:\Users\user1\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
I have C:\Users\user1\Anaconda3\ included in the system PATH environment variable. I have also reinstalled numpy multiple times. Any ideas?
When you use conda, this might come from the fact that conda has change the way it is activated in its latest version on windows. In particular, it has trouble loading DLLs when you are not in an activated conda environment.
By running your command python C:\dir\script.py from an active conda env (using conda activate for the base env for instance), you should see this issue disapear.
I'm working through a flask tutorial and am trying to run a script that creates a database instead of doing it through the command line. It uses the SQLAlchemy-migrate package, but when I try to run the script, it gives an ImportError.
This is the terminal output:
Sean:app seanpatterson$ python ./db_create.py
Traceback (most recent call last):
File "./db_create.py", line 2, in <module>
from migrate.versioning import api
ImportError: No module named migrate.versioning
This is the db_create.py script:
#!flask/bin/python
from migrate.versioning import api
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO
from app import db
import os.path
db.create_all()
if not os.path.exists(SQLALCHEMY_MIGRATE_REPO):
api.create(SQLALCHEMY_MIGRATE_REPO, 'database repository')
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
else:
api.version_control(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, api.version(SQLALCHEMY_MIGRATE_REPO))
This is the config file it references:
#!/usr/bin/env python
import os
basedir = os.path.abspath(os.path.dirname(__file__))
SQLALCHEMY_DATABASE_URI = 'sqlite:///' + os.path.join(basedir, 'app.db')
SQLALCHEMY_MIGRATE_REPO = os.path.join(basedir, 'db_repository')
This application is being run with a virtual environment. This are the module that relates to it that I have installed in the environment:
sqlalchemy_migrate-0.7.2-py2.7.egg-info
Any help appreciated
pip install sqlalchemy==0.7.9
and
pip install sqlalchemy-migrate==0.7.2
and
optionally this flask-whooshalchemy==0.55a should solve the problem
ImportError: No module named migrate.versioning probably means the module is not installed. Make sure it has been installed in the correct virtual environment, it is activated (you ran the activate script in that environment) and the selected Python binary is actually making use of that environment (i.e. you are using Python2 and not Python3).
As said by #BoppreH earlier
ImportError: No module named migrate.versioning
means that the module named 'migrate' is not installed in your virtual environment or your system. First make sure that you are using the proper environment and that it is activated using the activate script.
I had the same problem and had the correct environment set up. But still the error was not solved.
What worked for me was installing the sqlalchemy-migrate package from pip. After activating my environment, I ran the following code to install it :
pip install sqlalchemy-migrate
flask/bin/pip install flask-sqlalchemy without defining the version worked fine for me.
run :
easy_install Flask-SQLAlchemy
to install Flask-SQLAlchemy
sudo pip install flask-migrate
to install flask-migrate
I think this error might pop up for several obscure reasons, I would like to add another which I experienced:
I had the same exact error while having sqlalchemy-migrate correctly installed, and guess what, it didn't work just because I had named the migration script file as migrate.py, this created some conflict with the migrate package.
In fact PyCharm warned me with this message:
"Import resolves to its containing file... This inspection detects names that should resolve but don't."
I renamed the migration script as db_migrate.py and everything started working fine.
I could understand what was the issue cause I had another project with an identical set-up but with migrate-sqlalchemy working perfectly and the only difference was indeed that file name...
Hope this might help someone one day...
I had the same problem - "No module named migrate.versioning", and everything is much easier than we are talking about, you need to perform the commands "run"
file: db_create.py or file: db_migrate.py if you using PyCharm (not from the terminal). And you will have the expected output: "New migration saved as D:...there is my path...\microblog\db_repositort/versions/001_migration.py
Current database version: 1"