Fixing _all_ Jupyter notebook and `pytest` issues

Hi!

I’ve been finding the issues that others are reporting with pytest and running Jupyter Notebook.
I thought I’d put together the solution for the issues in a single place, to make other’s lives easier.

In all cases it’s assumed that you’ve installed python, some kind of virtual environment, and the requisites using pip install -r requirements.txt. The instructions are valid as of 2019-01-19; later versions of the tools might sort this out.

Errors running pytest

Symptoms: When trying to run pytest even in a simple case (such as pytest -m connection) there are lots of errors that don’t seem related to the “test” at hand.

From this thread:

SOLUTION: is uninstalling pytest, and installing pytest 3.3.2:

pip uninstall pytest
pip install pytest==3.3.2

Also, note that in the .ini file, pytest uses the connection data in the [TEST] section, so it’s perfectly possible that the “real” app test are passing via /status, and pytest is failing.

And, if you add comments to the file, they should be on its own line - a line like this Will fail (guess how I know! :smile:)

[TEST]
MFLIX_DB_URI = mongodb+srv://m220student:m220password@<URL>/test  ##This is a comment

Errors with junyper notebook

Symptoms: When trying to launch jupyter notebook, the webpage opens, but the notebook won’t “run” – and in the command prompt you get a lot of messages about “Kernel Restaring”, ending in:

ModuleNotFoundError: No module named 'prompt_toolkit.formatted_text

The reason: The issue is that the module prompt-toolkit version 1.0.15 is installed as a dependency of jupyter-console (v 5.2.0, which is the latest), and requires prompt-toolkit < 2.0.0. But ipython (and also ipykernel which depends on it) which is used by jupyter has a dependency of prompt-toolkit>=2.0.0.

SOLUTION: Uninstall ipython (whatever version got installed, in my case 7.2.0) and reinstall ipython == 6.5.0:

pip uninstall ipython
pip install ipython == 6.5.0

So far, everything appears to be working and no other errors have cropped out.

As mentioned above, it’s possible (likely?) that later version of these tools will sort this dependency issues and will remove this errors (or cause new ones!)

Thanks!

3 Likes

Don’t forget the tests must be run in the same directory as the .ini file, not the /test directory as one might expect.

  • That wasted sooo much of my time :frowning:
3 Likes

Hi, thank you so much for your help :smiley: I had both problems, but I only could fix the “pytest”. I’m still have the problem about jupyter notebook :frowning: . I made your solution, but it doesn’t work. Any other suggestions??

Hi Gabriela,

Can you share the output when you try run the jupyter notebook ? It would also be useful to see the output for your environment from the command pip list.

This might help determine if it’s a pip / library version mismatch.

Hope this helps!
Eoin

i got the jupyter notebook problem i can enter but i can’t run the cells:
tried the:
pip uninstall ipython
pip install ipython == 6.5.0
but i have an error with the install command

Hi Juan,

Could you check the spacing / white spaces on your pip ipython part ? I think there should be no white space between the library (ipython), the equals signs, and the version of the library.

Hope this helps!
Eoin

1 Like

oh thanks ! i was copy pasting the code in the fix post

Blockquote

To solve the prompt-toolkit error I changed the versions in several of the dependencies.

requirements.txt

Flask==0.12.4
Flask-Bcrypt==0.7.1
Flask-Login==0.4.0
pymongo==3.7.0
dnspython==1.15.0
pytest==3.3.0
pytest-flask==0.10.0
Flask-Cors==3.0.3
flask-jwt-extended==3.7.0
faker==0.8.13
jupyter==1.0.0
jupyter-client==5.2.4
jupyter-console==6.0.0
jupyter-core==4.4.0

You run pip install -r requirements.txt again and everything works ok.

1 Like

Thanks David,

I will have a look into to ensuring we update the requirements to catch this version issue with the prompt-toolkit pip installation.

Eoin

1 Like

Hi @brazileoin, here is my pip list and the output when I execute “jupyter notebook”…

Pip list:

Package Version


atomicwrites 1.3.0
attrs 19.1.0
backcall 0.1.0
bcrypt 3.1.6
bleach 3.1.0
cffi 1.12.2
Click 7.0
colorama 0.4.1
decorator 4.3.2
defusedxml 0.5.0
dnspython 1.15.0
entrypoints 0.3
Faker 0.8.13
flake8 3.7.7
Flask 0.12.4
Flask-Bcrypt 0.7.1
Flask-Cors 3.0.3
Flask-JWT-Extended 3.7.0
Flask-Login 0.4.0
ipykernel 5.1.0
ipython 6.5.0
ipython-genutils 0.2.0
ipywidgets 7.4.2
itsdangerous 1.1.0
jedi 0.13.3
Jinja2 2.10
jsonschema 3.0.1
jupyter 1.0.0
jupyter-client 5.2.3
jupyter-console 5.2.0
jupyter-core 4.4.0
MarkupSafe 1.1.1
mccabe 0.6.1
mistune 0.8.4
more-itertools 6.0.0
nbconvert 5.4.1
nbformat 4.4.0
notebook 5.7.6
pandocfilters 1.4.2
parso 0.3.4
pickleshare 0.7.5
pip 19.0.3
pluggy 0.6.0
prometheus-client 0.6.0
prompt-toolkit 1.0.15
py 1.8.0
pycodestyle 2.5.0
pycparser 2.19
pyflakes 2.1.1
Pygments 2.3.1
PyJWT 1.7.1
pymongo 3.7.0
pyrsistent 0.14.11
pytest 3.3.2
pytest-flask 0.10.0
python-dateutil 2.8.0
pywinpty 0.5.5
pyzmq 18.0.1
qtconsole 4.4.3
Send2Trash 1.5.0
setuptools 40.8.0
simplegeneric 0.8.1
six 1.12.0
terminado 0.8.1
testpath 0.4.2
text-unidecode 1.2
tornado 6.0.1
traitlets 4.3.2
wcwidth 0.1.7
webencodings 0.5.1
Werkzeug 0.14.1
wheel 0.33.1
widgetsnbextension 3.4.2

i got an error when execute pytest command. It was working ok till today :confused:

Hi @Juan_29875

Did you make any changes to your environment ? Did you activate your virtual environment / conda environment before running the tests ?

Kindest regards,
Eoin

*the only thing i installed today was this in visual studio code : asdf2

  • i did activate conda the first time when i was installing everything, do i need to activate again?

thank you for the answers

Hi @Juan_29875

If you have shutdown/rebooted/logged out then you will need to activate conda or the virtual environment again. They only last for the period of your terminal window so if you close that window then you will need to re-activate them.

If any of these happened since yesterday you should reactivate conda and try the pytest command again.

Hope this helps and let me know if it resolves your issue.
Eoin

i tried and have the same error 54519478_1046870452174396_618399140853841920_n

Hi @Juan_29875

Can you delete any old cached Pytest compiled Python files as these may be interfering with your pytest command ? These files (*.pyc) will in the tests\pycache directory which you can delete (it and the files will be regenerated as needed).

I would also ask that you double check your .ini file is correctly configured as per the README lesson in Chapter 1 in the section Running the Application.

Let me know if these help resolve your issues.

Kindest regards,
Eoin

I’m still having the same problem
i deleted the files in pycache
i doble checked the .ini file and it’s fine
i reinstaled conda
and restore the test files with the test files in the rar

Hi @Juan_29875

At this point, I’d suggest re-downloading and re-installing the mflix zip overwriting the existing directory, I’d suggest you copy this elsewhere to save your progress so far before overwriting it.

Let me know if this resolves the issue.

Eoin

This worked for me
Instead of
pip install -r requirements.txt
use
pip3 install -r requirements.txt

Otherwise it will hive permission denied errors or other errors as at pytest will not be able to find TEST server configuration in the config file