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
Related
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've deployed my first package in test.pypi.org as you can find it here
I have installed my package in my virtual environment (.venv).
$ pip list
returns :
Package Version
---------- -------
pip 20.1
pyupurs 0.0.2
setuptools 46.0.0
wheel 0.34.2
But as you can see here, I cannot import it within my interpreter.
Python 3.6.9 (default, Nov 7 2019, 10:44:02)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyupurs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pyupurs'
Why is this happening? How can I fix it?
In your package pyupurs there is nothing that can be imported under same name. The distribution package pyupurs installs top-level importable package named stateless_file_ops. So you can only do
import stateless_file_ops
If you want to change that you need to change you subdirectory structure perhaps adding a directory pyupurs with file __init__.py in it.
This has me completely bamboozled. I wanted to compile PyQt5. To do that I first need to compile and install sip. So I compiled and installed sip. Then I compiled and installed PyQt5. No problems so far. Then I tried it out.
$ python
Python 2.7.13 (default, Sep 26 2018, 18:42:22)
[GCC 6.3.0 20170516] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sip
>>> import PyQt5
>>> from PyQt5 import QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named sip
>>>
What??? I had to have sip installed to compile PyQt5. I had to have sip installed to import it. Why is it now telling me that there is "No module named sip?"
I had this problem with system packages (installed via apt), with a virtual env created with --system-site-packages, and I don't have it inside a proper virtual env. Python3.6, LinuxMint 19.
I had this problem when I was inside (venv) running the python from the venv/bin
it cleared and found sip when I used usr/bin/python
(in my setup they were the same versions, please check you product and setup that the virtual py is not needed)
I have multiple pythons installed in my machine, 2.7, 3.5, 3.6, etc and I installed the library called spacy.
And it seems like this library keeps referring to the old version of python which is 3.5. at /usr/local/lib/python3.5/dist-packages.
Python 3.6.5 (default, Mar 29 2018, 03:28:50)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import spacy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.5/dist-packages/spacy/__init__.py", line 4, in <module>
from . import util
File "/usr/local/lib/python3.5/dist-packages/spacy/util.py", line 4, in <module>
import ujson
ModuleNotFoundError: No module named 'ujson'
Regardless of this specific library 'spacy', I'd like to know
what is the best way to make library to point to upgraded python which is 3.6, not 3.5. Which path variable should I update?
Please help... I've been wasting too much time on this issue.
Try to install spacy lib by running pip with required python version in module mode:
python3.6 -m pip install spacy
After installing the TensorFlow CPU version with virtualenv (in Ubuntu 14.0), when I try to test the installation with Python (not from the source directory), I get the following error:
No module named tensorflow
Any explanation?
I am following the exact sequence of steps from the TensorFlow installation page.
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow
>>>
Tensoflow works only with Python 3.5.x version
Tensorflow does work with python 2.7 https://www.tensorflow.org/install/pip. Just wanted to add it here so no one get it wrong. Cant comment since I don't have the reputation yet :(
Check your env and pip to make sure you have installed it for the correct python version in the env.