How to run a module before install?
Peter Otten
__peter__ at web.de
Mon Jan 14 03:04:04 EST 2019
jfong at ms4.hinet.net wrote:
> I had download a module which has the following directory structure:
>
> [XL-Sudoku-Solver_master]
> |__[tests]
> |__[xl_sudoku_solver]
> |__setup.py |__ __init__.py
> |__problem1.txt |__ __main__.py
> |__README.md |__ ...
> |__ ...
>
> The setup.py file has something like this:
> ---------------------
> ...
> setup(
> name="xl-sudoku-solver",
> version="0.0.1.post3",
> packages=['xl_sudoku_solver'],
> entry_points={
> "console_scripts": [
> "xl-sudoku-solver = xl_sudoku_solver.__main__:main"
> ]
> },
> ...
> ----------------
>
> and the __main__.py has:
> ----------------
> ...
> from . import Solver, load_from_file, load_from_input, load_from_string
>
> def main():
> ...
>
> if __name__ == '__main__':
> main()
> ----------------
>
> The README.md suggest the way of running it:
>
> pip install xl-sudoku-solver
> $ xl-sudoku-solver --time -f problem1.txt
>
> But I like to run it before install. Is it possible? and how? I had try
> two ways below but niether works:
>
> 1) h:\Temp\XL-Sudoku-Solver-master>py xl_sudoku_solver --time -f
> problem1.txt Traceback (most recent call last):
> File "C:\Python34\lib\runpy.py", line 170, in _run_module_as_main
> "__main__", mod_spec)
> File "C:\Python34\lib\runpy.py", line 85, in _run_code
> exec(code, run_globals)
> File "xl_sudoku_solver\__main__.py", line 5, in <module>
> from . import Solver, load_from_file, load_from_input,
> load_from_string
> SystemError: Parent module '' not loaded, cannot perform relative import
>
> 2) h:\Temp\XL-Sudoku-Solver-master>py
> Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 19:28:18) [MSC v.1600 32
> bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for
> more information.
>>>> import xl_sudoku_solver
>>>>
>
> Can't find the name "main", What to do?
With h:\Temp\XL-Sudoku-Solver-master as the current working directory try
h:\Temp\XL-Sudoku-Solver-master>py -m xl_sudoku_solver
More information about the Python-list
mailing list