I'm working through the "Python Testing with Pytest" book.
I'm importing tinydb module to run assertions against it and terminal is giving
me error:
test_add_variety.py:1: in <module>
import pytest, tasks, tinydb
E ModuleNotFoundError: No module named 'tinydb'
however it is installed:
pip3 freeze:
click==7.1.2
six==1.16.0
tasks==0.1.0
tinydb==3.15.1
and I can also confirm by firing up Python interpreter:
(venv) mark#fid:~/p_test/ch2$ python
Python 3.8.10 (default, Sep 28 2021, 16:10:42)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tinydb
>>>
Please note that I'm running these with virtual environment activated.
Any suggestions why Pytest can't import tinydb module ?
Related
I installed django on my mac but i couldn't run my project as because this issue:
ModuleNotFoundError: No module named 'django'
I don't know about this, The problem is i couldn't import django on my system but tried this way too...
(my_project) my_project % python
Python 3.6.8 (v3.6.8:3c6b436a57, Dec 24 2018, 02:04:31)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
>>> import django
>>>
It's all fine, But i dont no the problem where is?
This happens if you have many python versions on your Mac, for example the Python version in your virtualenv is different from the default version of python.
Maybe you downloaded the django framework to other version.
You should look at the pip list See if you have Django
Trying to connect python to MySQL. Seem to be a lot on this issue but nothing seems to be working for me. If I am at the Python prompts I can enter my script line by line and have success.
>>> import mysql.connector as m
>>> m.__version__
'8.0.22'
But when I run the above two lines in my python script (named dbsql.py) I get the error:
File "C:\Users\gbran\PythonCode\dbsql.py", line 1, in <module>
import mysql.connector as m
ModuleNotFoundError: No mdoule named 'mysql'
I am new to Python, but wondering if this is a PATH issue within Widnows. Is there a way in the Python Prompt to see where the file mysql.connector is importing from to ensure the path is available for the script. Or is there something else I am missing here?
Thanks for any direction and help!
Use pip to search the available module
$ pip search mysql-connector | grep --color mysql-connector-python
mysql-connector-python-rf (2.2.2) - MySQL driver written in Python
mysql-connector-python (2.0.4) - MySQL driver written in Python
Install the mysql-connector-python-rf
$ pip install mysql-connector-python-rf
Verify
$ python
Python 2.7.11 (default, Apr 26 2016, 13:18:56)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
For python3 and later use the next command: $ pip3 install mysql-connector-python-rf
You can use sys module to find out the path from where mysql is getting imported.
In the example, I can see that my OS module is getting imported from /usr/lib/python3.8/os.py
>>> import sys
>>> import os
>>> sys.modules['os']
<module 'os' from '/usr/lib/python3.8/os.py'>
>>>
Then add that path to your PYTHONPATH so that python can import modules from there.
See another example below:
user#user-Inspiron:~$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sample_module
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'sample_module'
>>>
user#user-Inspiron:~$ echo $PYTHONPATH
user#user-Inspiron:~$ export PYTHONPATH=/tmp/
user#user-Inspiron:~$ echo $PYTHONPATH
/tmp/
user#user-Inspiron:~$ python3
Python 3.8.5 (default, Jul 28 2020, 12:59:40)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sample_module
>>> sample_module.does_it_work
'It Works!'
>>>
I'm trying to use the module pyelastix in PyDev but the line import pyelastix keeps yielding ImportError: No module named 'pyelastix'. I'm using a virtual environment called cv on Ubuntu 16.04. I tried the following commands to install pyelastix:
sudo pip install pyelastix
sudo pip3 install pyelastix
inside and outside of the virtual environment. Importing it in the CLI works fine:
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyelastix
>>>
In Eclipse, the PyDev Interpreter is set to /home/username/.virtualenvs/cv/bin/python3.5. The PYTHONPATH source folder is /${PROJECT_DIR_NAME}. What could be the issue here?
1) Module Azure-storage is installed:
sudo -H pip install azure-storage
Requirement already satisfied: azure-storage in /usr/local/lib/python2.7/dist-packages
2) In my python programme:
from azure.storage.table import TableService
gives me an error:
ImportError: No module named storage.table
3) However, if I open an interactive session I don't see the error:
sandeep#viepstesting:~$ python
Python 2.7.12+ (default, Sep 17 2016, 12:08:02)
[GCC 6.2.0 20160914] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from azure.storage.table import TableService
I went through the several post on this topic on this forum, nothing seems to work. E.g. tried setting PYTHONPATH to
/usr/local/lib/python2.7/dist-packages and /usr/local/lib/python2.7/dist-packages/
I will close this issue as I now think the problem was that i had a file named azure.py in the same directory.
It did not like the azure filename
I am using Django Rest Framework. When I try to go to the swagger docs page,
I am getting
ImportError: No module named drf_compound_fields
from serializers.py where I try to import the following
from drf_compound_fields.fields import ListField
I have drf-compound-field 0.2.2 in my virtualenv and I ran pip list command to make sure that it is installed.
Here is what I get from manage.py shell
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
>>>
>>>
>>>
>>> from drf_compound_fields.fields import ListField
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: No module named drf_compound_fields.fields
>>>
Thanks for your help!!
drf-compound-fields was installed under the same virtualenv where the django server was being run from.
Apparently, it needs to be installed at the system level and not necessarily at the virtualenv level.
Follow these steps to install drf-compound-fields package at system level:
Deactivate virtualenv.
pip install def-compound-fields
Activate virtualenv and start django process