Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not working in python 2.7 #159

Closed
gautamkrishnar opened this issue Aug 3, 2019 · 11 comments

Comments

@gautamkrishnar
Copy link
Owner

commented Aug 3, 2019

Issuehunt badges

While running https://github.com/gautamkrishnar/socli/tree/refactoring
I am getting the following error:

$ python -m socli for loop java
Traceback (most recent call last):
  File "/Users/gautam/miniconda3/envs/socli/1/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/Users/gautam/miniconda3/envs/socli/1/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/gautam/PycharmProjects/socli/socli/__main__.py", line 1, in <module>
    from socli.socli import main
  File "socli/socli.py", line 25, in <module>
    import socli.tui as tui
ImportError: No module named tui

This is related to python's module import difference between two versions.
https://stackoverflow.com/questions/30249119/difference-in-package-importing-between-python-2-7-and-3-4


IssueHunt Summary

Backers (Total: $10.00)

Submitted pull Requests


Become a backer now!

Or submit a pull request to get the deposits!

Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

@anirudnits

This comment has been minimized.

Copy link

commented Aug 3, 2019

Looking into it!

@gautamkrishnar

This comment has been minimized.

Copy link
Owner Author

commented Aug 3, 2019

We must make sure that it works on both 2x an 3x

@anirudnits

This comment has been minimized.

Copy link

commented Aug 3, 2019

while recreating the error, I got this
ModuleNotFoundError: No module named 'socli.tui'; 'socli' is not a package
is there anything that I am missing?

@anirudnits

This comment has been minimized.

Copy link

commented Aug 3, 2019

Sorry, I am able to create the same error in python2 but when the try the same thing in python3 I am getting the above error. Can you please verify if you are getting the same in python3?

@gautamkrishnar

This comment has been minimized.

Copy link
Owner Author

commented Aug 4, 2019

Working fine for me on python 3.7

@anirudnits

This comment has been minimized.

Copy link

commented Aug 4, 2019

I went through the files, changing
import socli.tui
to
import tui
should make it right.
From what I understand, the first import statement looks to import tui(maybe a function, variable or class) from socli.py file. The second import statement imports all the classes from tui.py file in the same directory.I guess that's what we are looking to do, please correct me if I'm wrong.

@issuehunt-app

This comment has been minimized.

Copy link

commented Aug 5, 2019

@issuehunt has funded $10.00 to this issue.


@gautamkrishnar

This comment has been minimized.

Copy link
Owner Author

commented Aug 5, 2019

@agarwalnishtha dont use import socli.tui. I need imports as python 3 standard. You can learn more about it here: https://stackoverflow.com/questions/12172791/changes-in-import-statement-python3

We must implement it using https://www.python.org/dev/peps/pep-0328/

@anirudnits

This comment has been minimized.

Copy link

commented Aug 6, 2019

Using sys.path.append(os.path.dirname(os.path.realpath(__file__))) should do the trick for both the versions.

When a module named spam is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file named spam.py in a list of directories given by the variable sys.path. sys.path is initialized from these locations:

The directory containing the input script (or the current directory when no file is specified).
PYTHONPATH (a list of directory names, with the same syntax as the shell variable PATH).
The installation-dependent default.

from https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html#basics-of-the-python-import-and-syspath

By adding the path of the current directory using sys.path.append, python will always search the current directory for the specified module.

@anirudnits

This comment has been minimized.

Copy link

commented Aug 10, 2019

Tested it and it works fine. Submitted the PR for the same. Let me know if there is anything wrong. Thanks!

gautamkrishnar added a commit that referenced this issue Aug 12, 2019

Fix for issue #159 (#162)
* Fixed the imports of the files in /socli directory to work for both python2.7 and python3

* Fixed the imports by adding the file directory in sys.path for the modules in /socli folder

* Fixed the imports of the files in /socli directory by adding the file directory in sys.path. Now it works for both versions python2 and python3

* Fixed the imports of the files in /socli directory by adding the file…

* Deleted the .vscode directory
@gautamkrishnar

This comment has been minimized.

Copy link
Owner Author

commented Aug 12, 2019

closing this one for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.