question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

from __future__ imports must occur at the beginning of the file

See original GitHub issue

I am using python 2.7 and when importing other packages from future than print_function, the temp_model.py file wraps the imports in a try and except block. The first lines in temp_model.py:

#coding=utf-8

from __future__ import print_function

try:
    from __future__ import unicode_literals
except:
    pass

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

15reactions
token-cjgcommented, Apr 15, 2019

Code in a jupyter notebook such as:

from __future__ import absolute_import, division, print_function

can be rewritten as:

exec('from __future__ import absolute_import, division, print_function')

7reactions
zhangyi6commented, Jul 19, 2018

I got the same problem, did you gays solve this with the seperated python file?

Read more comments on GitHub >

github_iconTop Results From Across the Web

"from __future__ imports must occur at the beginning of the file ...
The first string is elided from the code as a docstring, but the second string becomes a statement in the code consisting of...
Read more >
syntaxerror: from __future__ imports must occur at the ...
When using the --coverage option with a source file with a __future__ import statement at the top the following error occurrs: SyntaxError: from...
Read more >
from __future__ imports must occur at the beginning of the file
Answer a question The Python script ''' a ''' from __future__ import print_function works well (i.e., does nothing), but ''' a ''' '''...
Read more >
from __future__ imports "must occur at the beginning of the file
hi i am developing web services on MAC SYSTEM by using python-SOAP-ZSI tool. but i am getting this error ...
Read more >
"from __future__ import print_function" fails on Sage scripts
File "test.sage.py", line 6 from __future__ import print_function SyntaxError: from __future__ imports must occur at the beginning of the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found