cancel
Showing results for 
Search instead for 
Did you mean: 

Flask configuration for training

Hello,
I'm trying to setup the Neo4J-Flask course but, after some tries I still receive the same error when launch Flask run command:
"Error: While importing 'api', an ImportError was raised."
below the full cmd log.
New to Flask configuration (Windows).
Thanks for hints.
Best regards

(sandbox) C:\VirtualEnv\Neo4J_Flask>flask run

  • Serving Flask app 'api' (lazy loading)
  • Environment: development
  • Debug mode: on
    Usage: flask run [OPTIONS]
    Try 'flask run --help' for help.

Error: While importing 'api', an ImportError was raised.

10 REPLIES 10

adam_cowley
Neo4j
Neo4j

Hey Roberto, Welcome to the community!

I hate these errors! When I've come across this before I have added PYTHONPATH=. to the command which seemed to fix it. There are a couple of hints here that may also help you solve the problem.

Hey Adam, I run into same problem as Roberto. Trying to setup Building Neo4J Application with Python ends up with:

(sandbox) app-python % flask run
flask run

  • Serving Flask app 'api' (lazy loading)
  • Environment: development
  • Debug mode: on
    Usage: flask run [OPTIONS]
    Try 'flask run --help' for help.
    Error: While importing 'api', an ImportError was raised.

Same holds for all hints from Help, failing on "flask run", e.g.:

(sandbox) app-python % FLASK_APP=api FLASK_ENV=development flask run
FLASK_APP=api FLASK_ENV=development flask run

  • Serving Flask app 'api' (lazy loading)
  • Environment: development
  • Debug mode: on
    Usage: flask run [OPTIONS]
    Try 'flask run --help' for help.
    Error: While importing 'api', an ImportError was raised.

I'm using: macOS 12.2.1, zsh 5.8, Python 3.10.4, pip 22.0.4

Any ideas ? Thanks!

Nana30
Node

Hi there,

so, after nearly throwing in the towel,  I found a solution for me: I had the wrong Python-Version (3.10) installed. Uninstalled Version 3.10 and installing Version 3.9 works now for me. Maybe the course designer could mark that with some color, that the Python version is crucial!

Hopefully I can do the course without any further obstacles now 😉

 

thank you I had the same problem and you solution worked for me too!

I confirm this, thank you!!

emack
Node

Hello all, is there a way to do this in Windows with python 3.10? I am getting the same error as above...

BTW as an FYI for Window cmd some of the code in the project setup is different:

  1. sandbox\Scripts\activate instead of source sandbox/bin/activate
  2. copy .env.example .env instead of cp .env.example .env

 

Hi,

I didn't find a solution. In order to make it work, the project needs to be rewritten with python 3.10 I think. 

youjuin
Node

'Flask run' command only  can be run under python-3.9.

(sandbox) PS C:\Users\ychen70\Downloads\app-python-main> python --version
Python 3.9.13
(sandbox) PS C:\Users\ychen70\Downloads\app-python-main> Flask run
* Serving Flask app 'api' (lazy loading)
* Environment: development
* Debug mode: on
* Restarting with stat
* Debugger is active!
* Debugger PIN: 412-471-481
* Running on http://127.0.0.1:3000/ (Press CTRL+C to quit)

gerard300
Node

Hi,

As an alternative you can use conda instead of venv (so frustating)

conda create -n pthon-neo4j python=3.9

(Mac Path) --> /Users/<your_user>/opt/anaconda3/envs/pthon-neo4j/bin/pip install -r requirements.tx
And then 
flask run

That worked for me!