ImportError: cannot import name print_function [on hold]

888
January 21, 2017, at 1:12 PM

Stuck at the following error - ImportError

Traceback (most recent call last):
  File "SparkToRedshiftConnector.py", line 1, in <module>
    from future import print_function
ImportError: No module named future

Hence installed future

[root@chai analyticsTool]# pip install future
Collecting future
  Downloading future-0.16.0.tar.gz (824kB)
    100% |████████████████████████████████| 829kB 155kB/s 
Installing collected packages: future
  Running setup.py install for future ... done
Successfully installed future-0.16.0

Retried to get the same error

[root@chai analyticsTool]# python SparkToRedshiftConnector.py 
Traceback (most recent call last):
  File "SparkToRedshiftConnector.py", line 1, in <module>
    from future import print_function
ImportError: cannot import name print_function

Later tried

Installing print_function

$ pip install print_function
Collecting print_function
  Could not find a version that satisfies the requirement print_function (from versions: )
No matching distribution found for print_function

Installing __future__ instead of future

[root@chai analyticsTool]# pip install __future__
Invalid requirement: '__future__'
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/pip/req/req_install.py", line 82, in __init__
    req = Requirement(req)
  File "/usr/lib/python2.7/site-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
InvalidRequirement: Invalid requirement, parse error at "'__future'"

Still error persisted of import

Answer 1

Solution -

In the code instead of

from future import print_function

Re-edit it

from __future__ import print_function
READ ALSO
How to access iter_size variable in Python (Caffe)?

How to access iter_size variable in Python (Caffe)?

I am trying to read the parameters of the solverprototxt file in Python

423
Count occurrence of a character in a string

Count occurrence of a character in a string

What's the simplest way to count the number of occurrences of a character in a string?

488
PyGame List Index Issue With High Score

PyGame List Index Issue With High Score

One of the requirements for my PyGame is to implement a basic high score function (showing the name and score)My database for the highscore works perfectly fine, as it stores a "sub-list" into the entire database list: such as [['Bob',10],['Jim',17]]

379
How to get the url address from upper function in Scrapy?

How to get the url address from upper function in Scrapy?

In my Scrapy spiderpy, see the last two rows

382