What should I do solving this print_function eror in anaconda.
I write the below code,
from _future_ import print_function
But it show an error and that is,
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-fd1a0773c2f5> in <module>
----> 1 from _future_ import print_function
ModuleNotFoundError: No module named '_future_'
Note: I uam using created environment as py36. because I it was to difficult to install ensorflow and keras where I used Python 3.7 . That's why I create new environment where python version is Python 3.6.0 .
There are two underscores on both sides of Python's __future__ module, so your import should be:
from __future__ import print_function
Related
I'm unable to install stackstac on Google Colab. This is reproducible with the code below.
!pip install stackstac
import stackstac
outputs:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-c01f370957f7> in <module>()
1 get_ipython().system('pip install stackstac')
----> 2 import stackstac
1 frames
/usr/local/lib/python3.7/dist-packages/stackstac/rio_reader.py in <module>()
5 import threading
6 import weakref
----> 7 from typing import TYPE_CHECKING, Optional, Protocol, Tuple, Type, Union
8
9 import numpy as np
ImportError: cannot import name 'Protocol' from 'typing' (/usr/lib/python3.7/typing.py)
---------------------------------------------------------------------------
Same issue on a local instance how ever that solution doesn't translate.
Protocol was introduced to typing as of Python 3.8, as can be seen in the docs. You appear to be running Python 3.7, based on your file paths - upgrade to use Python 3.8 or later if you can.
I am running a script and I am getting the error:
Traceback (most recent call last):
File "common/tensorflow/run_tf_benchmark.py", line 30, in <module>
from common.base_benchmark_util import BaseBenchmarkUtil
ModuleNotFoundError: No module named 'common'
I am running on an ec2 instance with the following AMI: Deep Learning AMI (Ubuntu 16.04) Version 25.0 (ami-025c308193ac1a136) and I am also working in the tensorflow_p36 anaconda environment that comes from the AMI. My Ubuntu directory is structured as so:
home
--ubuntu
--benchmark_models
--benchmark
--common
--__init__.py
--base_benchmark_util.py
--tensorflow
--run_tf_benchmark.py
--__init__.py
Note, there are other files in the directory, but these are the relevant python files.
Currently, the imports at the top of run_tf_benchmark.py are
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
sys.path.append('/home/ubuntu/benchmark_models/benchmarks/common')
print(sys.path)
from argparse import ArgumentParser
from common.base_benchmark_util import BaseBenchmarkUtil
and the printed sys.path is
['/home/ubuntu/benchmark_models/benchmarks/common/tensorflow', '/home/ubuntu/src/cntk/bindings/python',
'/home/ubuntu/benchmark_models/models/image_recognition/tensorflow/mobilenet_v2', '/home/ubuntu/models',
'/home/ubuntu/models/research', '/home/ubuntu/models/research/slim',
'/home/ubuntu/anaconda3/lib/python36.zip', '/home/ubuntu/anaconda3/lib/python3.6',
'/home/ubuntu/anaconda3/lib/python3.6/lib-dynload', '/home/ubuntu/anaconda3/lib/python3.6/site-packages',
'/home/ubuntu/benchmark_models/benchmarks/common']
I can clearly see common in the python path, but the import error still happens. What am I doing wrong?
Just remove 'common' while importing because you are already in 'common' directory
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import sys
sys.path.append('/home/ubuntu/benchmark_models/benchmarks/common')
print(sys.path)
from argparse import ArgumentParser
from base_benchmark_util import BaseBenchmarkUtil
Alright, I solved the issue. The issue was that I added /home/ubuntu/benchmark_models/benchmarks/common, not /home/ubuntu/benchmark_models/benchmarks/. By import benchmarks, it also allowed all of my other code to import common as well.
I'm regularly importing Matplotlib Numpy PySide2 in Atom. They unexpectedly cannot be import for an unknown reason and then appear to be again re-importable, again unexplained.
When trying to import matplotlib with the following command
import matplotlib.pyplot as plt
This scripts runs without problems when I run in a Jupyter notebook or through the Terminal. But When trying to run on Hydrogen in Atom, I get the following error message:
File "<ipython-input-3-3dc8365ef973>", line 6
ModuleNotFoundError: No module named 'matplotlib.backends'; 'matplotlib' is not a package
^
SyntaxError: invalid syntax
I get the same error with Pyside2 when trying to run the line
from PySide2.QtWidgets import QApplication, QLabel
I get the error message
ModuleNotFoundError: No module named 'PySide2.QtWidgets'; 'PySide2' is not a package
Here is the path of python (after having typed which python in the Terminal): /anaconda3/bin/python
I checked that the matplotlib is installed by running the command conda list in the Terminal and got (among all the other packages) those lines:
matplotlib 2.1.2 py36h6d6146d_0
matplotlib 2.2.2 <pip>
PySide2 5.9.0a1.dev1525348214
I tried to run the following command in the Terminal but didn't solve the problem
sudo apt-get install python3-matplotlib
sudo pip3 install matplotlib
I had a similar issue with numpy when trying to import import numpy. Although import numpy was not a problem an hour ago, I get now the following error message (it seems it wants to connect to a previously used script in which numpy was used, to open numpy itself):
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-5-592c151f282b> in <module>()
1 # from numpy import genfromtxt as gft
----> 2 import numpy
~/Downloads/numpy.py in <module>()
----> 1 from numpy import genfromtxt
2 my_data = genfromtxt('/Users/mymac/Documents/PyQt/image_viewer/csv_file_generator/eggs.csv',
3 delimiter=',',
4 dtype=None,
5 encoding=None)
ImportError: cannot import name 'genfromtxt'
I had the same issue when tryin to import opencv2: I got the following error message:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
ImportError: numpy.core.multiarray failed to import---------------------------
------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-8f6675581547> in <module>()
5 from PySide2.QtCore import *
6 from PySide2.QtGui import *
----> 7 import cv2
8 import numpy
9 import csv
ImportError: numpy.core.multiarray failed to import
I visited the following site which didn't help me (or I didn't understand how to implement exactly the steps to fix the problem)
ImportError: No module named matplotlib.pyplot
Importing matplotlib.pyplot in atom editor
matplotlib Error: No module named matplotlib even though it is installed
I'm running on/with
python 3.6.5
macOS 10.13.4
Atom 1.27.0 x64
Hydrogen 2.4.1
I'm trying to import zipline.transforms, but the output message says No module named transforms. I'm using python2.7 and downloaded zipline via conda.
from zipline.transforms import batch_transforms
ImportErrorTraceback (most recent call last)
<ipython-input-55-253f85965feb> in <module>()
----> 1 from zipline.transforms import batch_transform
ImportError: No module named transforms
First, is your IDE (pycharm or sublime) included Anaconda in the path? Second, please check where you zipline module was installed, usually .../lib/python2.7/site-packages/zipline, does it include a module called "transforms"? maybe it's an old module, not in the updated zipline anymore.
I have written a package named biographs with the following architecture:
biographs (folder)
>biographs (package)
>__init__.py
>bpdb.py
>pmolecule.py
>bgraph.py
>bspace.py
The __init__.py file is only the following:
from .pmolecule import Pmolecule
When I'm working in ipython3 and I want to import biographs (only to use the class Pmolecule), I get the following error in ipython3 (Ipython 6.0.0, Python 3.6.1):
In [1]: cd ~/biographs/
/Users/rdora/biographs
In [2]: import biographs
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-2-1803e6928e0e> in <module>()
----> 1 import biographs
/Users/rdora/biographs/biographs/__init__.py in <module>()
----> 1 from .pmolecule import Pmolecule
/Users/rdora/biographs/biographs/pmolecule.py in <module>()
1 # class to deal with protein structures
2 # python 2
----> 3 import bpdb
4 import bgraph
5 import bspace
ModuleNotFoundError: No module named 'bpdb'
However when I do exactly the same process using IPython 5.3.0 with Python 2.7.13 there is no error message.
Thank you
This is because of how imports work in Python 2 and Python 3. In your module pmolecule.py you apparently do import bpdb. In Python 2 this will search the local directory for a module called bpdb.py and import it. However in Python 3 you must be explicit about those relative imports, i.e. you need to do
from . import bpdb
In order to get consistency for Python 2 you can use from __future__ import absolute_imports which prohibits such non-explicit imports also under Python 2.
Note that the same holds for:
----> 3 import bpdb
4 import bgraph
5 import bspace
Those need to be imported via from . import <module-name> syntax.
Further reading
What's new in Python 3 -- Removed Syntax
PEP 328 -- Imports: Multi-Line and Absolute/Relative