After installing factory_boy, imports are not recognized. - django

Pip install factory_boy seems to install the package without problems. Running pip freeze shows me:
Django==1.7
dj-database-url==0.3.0
dj-static==0.0.6
django-toolbelt==0.0.1
factory-boy==2.4.1
gunicorn==19.1.1
static3==0.5.1
However, when I edit my tests to put import factory or import factory.django... I get the result:
Traceback (most recent call last):
File "C:\Python27\lib\unittest\loader.py", line 252, in _find_tests
module = self._get_module_from_name(name)
File "C:\Python27\lib\unittest\loader.py", line 230, in _get_module_from_name
__import__(name)
File "C:\Users\Jeff\Projects\gamematch2\eventbook\tests.py", line 6, in <modul
e>
import factory.django
ImportError: No module named factory.django
I've followed the advice in:
Trouble installing factory_boy with pip
with no results.
Not sure how to proceed, any help would be appreciated.

Appears to be a problem with my virtual environment. Exiting virtualenv, installing factory_boy again, and then running manage.py test again works successfully. Not fully solved, but at least I have a work around.

Related

Try to get variable type on python3 on macOS and it show the below error

Traceback (most recent call last): File "/Users/kane/study/python/basicDataStructure/liner_data_structure.py", line 2, in <module> from turtle import clear File "/usr/local/Cellar/python#3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/turtle.py", line 107, in <module> import tkinter as TK File "/usr/local/Cellar/python#3.9/3.9.7_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/tkinter/__init__.py", line 37, in <module> import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter'
Note Please note that, I didn't use anything regarding tkinter. I only created a variable and checked its type.
I have found the answer at the link
brew install python-tk
You will have to firstly import it on the os device!
Run these in your terminal
python3 get-pip.py
Pip install turtle
Pip install tkinter

import apache_beam metaclass conflict

When I try to import apache beam I get the following error.
>>> import apache_beam
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/toor/pfff/local/lib/python2.7/site-packages/apache_beam/__init__.py", line 78, in <module>
from apache_beam import io
File "/home/toor/pfff/local/lib/python2.7/site-packages/apache_beam/io/__init__.py", line 21, in <module>
...
from apitools.base.protorpclite import messages
File "/home/toor/pfff/local/lib/python2.7/site-packages/apitools/base/protorpclite/messages.py", line 1165, in <module>
class Field(six.with_metaclass(_FieldMeta, object)):
TypeError: Error when calling the metaclass bases
metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
I'm working in a new virtual environment in which I have installed apache_beam by installing google-cloud-dataflow with pip as I need the version that is able to run on google cloud platform.
pip install google-cloud-dataflow
I have no idea how to solve this error. For completeness, I'm using python 2.7.12 on bash on ubuntu on Windows. My colleague had the same error when running it on bash on ubuntu on Windows, while directly running on Windows is working fine.
The installed versions of the packages are:
>>> pip freeze
apache-beam==2.1.0
avro==1.8.2
cachetools==2.0.1
certifi==2017.7.27.1
chardet==3.0.4
crcmod==1.7
dill==0.2.6
enum34==1.1.6
funcsigs==1.0.2
future==0.16.0
futures==3.1.1
gapic-google-cloud-pubsub-v1==0.15.4
google-apitools==0.5.11
google-auth==1.1.0
google-auth-httplib2==0.0.2
google-cloud-bigquery==0.25.0
google-cloud-core==0.25.0
google-cloud-dataflow==2.1.0
google-cloud-pubsub==0.26.0
google-gax==0.15.15
googleapis-common-protos==1.5.2
googledatastore==7.0.1
grpc-google-iam-v1==0.11.3
grpcio==1.6.0
httplib2==0.9.2
idna==2.6
mock==2.0.0
oauth2client==3.0.0
pbr==3.1.1
pkg-resources==0.0.0
ply==3.8
proto-google-cloud-datastore-v1==0.90.4
proto-google-cloud-pubsub-v1==0.15.4
protobuf==3.3.0
pyasn1==0.3.5
pyasn1-modules==0.1.4
PyYAML==3.12
requests==2.18.4
rsa==3.4.2
six==1.11.0
urllib3==1.22
Downgrade six to version 1.10.0
pip install six==1.10.0

ImportError: libcusolver.so.8.0: cannot open shared object file: No such file or directory

Possible duplicate of this question.
I have a gpu account to whom I connect through putty (ssh login). I have created a virtualenv there and I am installing tenorflow through pip for gpu. Everything works fine, when I run command
$ pip list
following list is being shown:
backports.weakref (1.0rc1)
bleach (1.5.0)
funcsigs (1.0.2)
html5lib (0.9999999)
Markdown (2.6.8)
mock (2.0.0)
numpy (1.13.1)
olefile (0.44)
pbr (3.1.1)
Pillow (4.2.1)
pip (9.0.1)
protobuf (3.3.0)
setuptools (36.0.1)
six (1.10.0)
tensorflow-gpu (1.2.1)
Werkzeug (0.12.2)
wheel (0.29.0)
But when I run:
$ python
>>> import tensorflow
It shows the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/__init__.py", line 49, in <module>
from tensorflow.python import pywrap_tensorflow
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/pywrap_tensorflow.py", line 52, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/pywrap_tensorflow.py", line 41, in <module>
from tensorflow.python.pywrap_tensorflow_internal import *
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/pywrap_tensorflow_internal.py", line 28, in
<module>
_pywrap_tensorflow_internal = swig_import_helper()
File "/home/nauman/junaid/final/test/lib/python2.7/site-
packages/tensorflow/python/pywrap_tensorflow_internal.py", line 24, in
swig_import_helper
_mod = imp.load_module('_pywrap_tensorflow_internal', fp, pathname,
description)
ImportError: libcusolver.so.8.0: cannot open shared object file: No such
file or directory
Failed to load the native TensorFlow runtime.
See https://www.tensorflow.org/install/install_sources#common_installation_problems
for some common reasons and solutions. Include the entire stack trace
above this error message when asking for help.
I have also set my environment variables like this:
export CUDA_HOME=/opt/cuda
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64:$CUDA_HOME/extras/CUPTI/lib64"
Moreover, I found that libcusolver.so.8.0 is not there, while libcusolver.so.7.5
is there in cuda/lib64/.
Somehow tensorflow is finding wrong file or I ain't know nothing.
Any help would be appreciated as I am new to all this stuff.
Python version: 2.7
OS: Linux
This may be connected to the incorrect linking of your libraries.
Simply run sudo ldconfig /usr/local/cuda/lib64. It solved for me.
If you need to know more: ldconfig man page.
I solved the issue. Actually I have cuda 7.5 installed and I was installing latest tensorflow version which probably support cuda 8.0.
So I downgraded.
pip install --upgrade \ https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.10.0-cp27-none-linux_x86_64.whl
If you installed tensorflow-gpu by using pip with prebuilt .whl, the cuda version were fixed. As far as I know, starting 0.11.0rc1, all the prebuilt packages are now built for cuda 8. So there are two ways to solve the problem:
install cuda 8 for the prebuilt packages tensorflow-gpu >= 0.11.orc1
keep cuda 7.5 stay, then build tensorflow-gpu from source code
If you are using cuda-9.0 try sudo apt install nvidia-cuda-dev (if you are using an Ubuntu distribution)

trouble importing skllearn

Hi i have installed the Scikit-learn but i keep getting error msgs when i try to import the sklearn module. it shows the following msg. anyone knows what's going on?
import sklearn
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sklearn/__init__.py", line 31, in <module>
from . import __check_build
File "sklearn/__check_build/__init__.py", line 46, in <module>
raise_build_error(e)
File "sklearn/__check_build/__init__.py", line 41, in raise_build_error
%s""" % (e, local_dir, ''.join(dir_content).strip(), msg))
ImportError: No module named _check_build
___________________________________________________________________________
Contents of sklearn/__check_build:
__init__.py __init__.pyc _check_build.c
_check_build.pyx setup.py setup.pyc
___________________________________________________________________________
It seems that scikit-learn has not been built correctly.
If you have installed scikit-learn from source, please do not forget
to build the package before using it: run `python setup.py install` or
`make` in the source directory.
If you have used an installer, please check that it is suited for your
Python version, your operating system and your platform.
As you can see in your errors: ImportError: No module named _check_build in that directory it has .c file and it never compiled.
If you check this link you will see many parts of scikit-learn has been written in C.
So for installing this kind of packages , you need to install python-dev package in your system.
python-dev package will install many C headers like python.h.
So install python-dev package in your system and then remove and install scikit-learn package again.

python3.2 + virtualenv - env create failed

I've got a py2.7 project which I want to test under py3.2. For this purpose, I want to use virtualenv. I wanted to create an environment that would run 3.2 version internally:
virtualenv 3.2 -p /usr/bin/python3.2
but it failed. My default python version is 2.7 (ubuntu default settings). Here is virtualenv --version 1.10. The error output is:
Running virtualenv with interpreter /usr/bin/python3.2
New python executable in 3.2/bin/python3.2
Also creating executable in 3.2/bin/python
Installing Setuptools...................................................................................................................................................................................................................................done.
Installing Pip..............
Complete output from command /home/tomasz/Develop...on/3.2/bin/python3.2 setup.py install --single-version-externally-managed --record record:
Traceback (most recent call last):
File "setup.py", line 5, in <module>
from setuptools import setup, find_packages
File "/usr/lib/python2.7/dist-packages/setuptools/__init__.py", line 2, in <module>
from setuptools.extension import Extension, Library
File "/usr/lib/python2.7/dist-packages/setuptools/extension.py", line 2, in <module>
from setuptools.dist import _get_unpatched
File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 103
except ValueError, e:
^
SyntaxError: invalid syntax
----------------------------------------
...Installing Pip...done.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 2308, in <module>
main()
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 821, in main
symlink=options.symlink)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 963, in create_environment
install_sdist('Pip', 'pip-*.tar.gz', py_executable, search_dirs)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 932, in install_sdist
filter_stdout=filter_install_output)
File "/usr/local/lib/python2.7/dist-packages/virtualenv.py", line 899, in call_subprocess
% (cmd_desc, proc.returncode))
OSError: Command /home/tomasz/Develop...on/3.2/bin/python3.2 setup.py install --single-version-externally-managed --record record failed with error code 1
I don't know what the hell is this syntax error - where does it come from... I know there was a change in try...catch statement syntax between 2.x and 3.x, but should virtualenv throw syntax errors?
I'd be grateful if someone pointed me out if there's something I'm doing wrong or if there is an installation problem on my machine.
To create a Python 3.2 virtual environment you should use the virtualenv you installed for Python 3.2. In your case that would be:
/usr/bin/virtualenv-3.2
You'll have to use a Python 3 version of virtualenv; the version you are using is installing Python 2 tools into a Python 3 virtual environment and these are not compatible.
virtualenv --python=/usr/bin/python3.2 --no-site-packages ENV