Python Forum
[split] Help- converting file with pyton script - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: [split] Help- converting file with pyton script (/thread-34152.html)



[split] Help- converting file with pyton script - eltomassito - Jul-01-2021

Is it possible to get another help with this script https://github.com/ypomortsev/ccss2edr?
How to run it after installing default python environment
I’ve tried to run it in cmd when I’m in C:\ccss2edr-master\ccss2edr folder by: python ccss2edr.py but then get error:

Error:
Traceback (most recent call last): File "C:\ccss2edr\ccss2edr\ccss2edr.py", line 7, in <module> from .cgats import CGATS ImportError: attempted relative import with no known parent package
If I try to remove dots before cgatds and edr to loook like this:

from .cgats import CGATS   -> from cgats import CGATS
from .edr import (  ->  from edr import (
then got error:

Error:
Traceback (most recent call last): File "C:\ccss2edr\ccss2edr\ccss2edr.py", line 8, in <module> from edr import ( File "C:\ccss2edr\ccss2edr\edr.py", line 3, in <module> from record import recordtype File "C:\ccss2edr\ccss2edr\record.py", line 130 exec template in namespace ^ SyntaxError: Missing parentheses in call to 'exec'
If tried to modify it further with couple of next errors from:

try:
        exec template in namespace
        if verbose: print template
    except SyntaxError, e:
to:

try:
        exec (template, namespace)
        if verbose: print (template)
    except SyntaxError as e:
but got next error

Error:
Traceback (most recent call last): File "C:\ccss2edr\ccss2edr\ccss2edr.py", line 8, in <module> from edr import ( File "C:\ccss2edr\ccss2edr\edr.py", line 3, in <module> from record import recordtype File "C:\ccss2edr\ccss2edr\record.py", line 147 print TestResults(*doctest.testmod()) ^ SyntaxError: invalid syntax
I’ve tried to run it in another way in cmd when I’m in C:\ccss2edr-master\ by: python –m ccss2edr\ccss2edr but got another error:

Error:
Traceback (most recent call last): File "C:\Program Files\Python39\lib\runpy.py", line 197, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Program Files\Python39\lib\runpy.py", line 87, in _run_code exec(code, run_globals) File "C:\ccss2edr\ccss2edr\ccss2edr.py", line 8, in <module> from .edr import ( File "C:\ccss2edr\ccss2edr\edr.py", line 3, in <module> from record import recordtype ModuleNotFoundError: No module named 'record'
I’ve tried another method too. I found Python 2.0.1 and installed on Clean Windows 7. No chances to install ccss2edr script. After execute in cmd: "python setup.py" I've got error: "error in setup script: invalid distribution option 'entry_points'"
Then I installed Python 2.7.9 and execute: "python setup.py install". After that run "python ccss2edr.py -h" and the same as errors as above:

Error:
Traceback (most recent call last): File "ccss2edr.py", line 7, in <module> from .cgats import CGATS ValueError: Attempted relative import in non-package
I’ve tried it on Ubuntu machine with Python2 too but got the same errors :(

Can someone help me? I’m fighting with it third day and no success. I don't know why it’s so hard to execute it?


RE: [split] Help- converting file with pyton script - buran - Jul-01-2021

Did you try to install it?
Note this is python 2 script, based on exec and print being statements in record.py and also using basestring. Although in some other modules it's used like function.
Also you need to change
from record import recordtype
to
from .record import recordtype


RE: [split] Help- converting file with pyton script - eltomassito - Jul-02-2021

(Jul-01-2021, 02:57 PM)buran Wrote: Did you try to install it?

Yes I've tried. An then I run it from created folder: "\build\lib\ccss2edr\" But after execute I got error:
Error:
"Error: Traceback (most recent call last): File "C:\ccss2edr\ccss2edr\ccss2edr.py", line 7, in <module> from .cgats import CGATS ValueError: Attempted relative import in non-package"



RE: [split] Help- converting file with pyton script - eltomassito - Jul-02-2021

Finally success! Maybe Python version is the key? I've used python-2.7.9.msi version. It doesn't work with python3 and probably with other version then 2.7.9.

The only change I've made was modifing ccss2edr.py by removing dots:
from .cgats import CGATS   -> from cgats import CGATS
from .edr import (  ->  from edr import (
Then I could execute script without installation. For example: python ccss2edr.py --tech-type 2 crt.ccss crt.edr (--tech-type number you can find in edr.py file).

And I recommend to use newer version of script (with more display types) from: https://github.com/mironovd/ccss2edr

Thanks for help.


RE: [split] Help- converting file with pyton script - snippsat - Jul-02-2021

Looking at setup.py so should this create .exe files of ccss2ed and dumpedr.
Look in you Python27 Scripts folder to see i there is ccss2ed.exe and dumpedr.exe,then i folder cmd try to run --help on files.

Can do a quick test as this in an old Python 2 project i run virtual environment with Virtualenv,Python 3 has build in venv.
# Make
C:\Python27\Scripts
λ virtualenv -p C:\python27\python.exe cc_venv
created virtual environment CPython2.7.18.final.0-64 in 1440ms  

# Cd in
C:\Python27\Scripts
λ cd cc_venv\

# Activate
C:\Python27\Scripts\cc_venv
λ C:\Python27\Scripts\cc_venv\Scripts\activate.bat

# Clone down
(cc_venv) C:\Python27\Scripts\cc_venv
λ git clone https://github.com/ypomortsev/ccss2edr.git
Cloning into 'ccss2edr'...
remote: Enumerating objects: 16, done.
remote: Total 16 (delta 0), reused 0 (delta 0), pack-reused 16
Unpacking objects: 100% (16/16), done.
Checking connectivity... done.

# Cd in
(cc_venv) C:\Python27\Scripts\cc_venv
λ cd ccss2edr\

(cc_venv) C:\Python27\Scripts\cc_venv\ccss2edr (master)
λ ls
LICENSE  README.md  ccss2edr/  setup.py

(cc_venv) C:\Python27\Scripts\cc_venv\ccss2edr (master)
λ python -V
Python 2.7.18

# Install
(cc_venv) C:\Python27\Scripts\cc_venv\ccss2edr (master)
λ python setup.py install
running install
.....
Finished processing dependencies for ccss2edr==0.0.1

# Test
(cc_venv) C:\Python27\Scripts\cc_venv\ccss2edr (master)
λ ccss2edr --help
usage: ccss2edr [-h] [--tech-type TECH_TYPE] ccss out

Convert a .ccss file to .edr

positional arguments:
  ccss                  .ccss input filename
  out                   .edr output filename

optional arguments:
  -h, --help            show this help message and exit
  --tech-type TECH_TYPE
                        technology type


 # Test convert a ccss file,it works
(cc_venv) C:\Python27\Scripts\cc_venv\ccss2edr (master)
λ ccss2edr test1.ccss test_out.edr



RE: [split] Help- converting file with pyton script - eltomassito - Jul-02-2021

(Jul-02-2021, 10:16 AM)snippsat Wrote: Look in you Python27 Scripts folder to see i there is ccss2ed.exe and dumpedr.exe,then i folder cmd try to run --help on files.

Yes. There are ccss2edr.exe and dumpedr.exe in this folder. And this exe works but if I copy it to another computer then ccss2edr.exe is unusable.


RE: [split] Help- converting file with pyton script - snippsat - Jul-02-2021

(Jul-02-2021, 01:21 PM)eltomassito Wrote: Yes. There are ccss2edr.exe and dumpedr.exe in this folder. And this exe works but if I copy it to another computer then ccss2edr.exe is unusable.
Yes,these are not stand alone .exe,so need to run same install on other Pc.
Can search for pyinstaller entrypoint to try to make it standalone with Pyinstaller.
Can also use miniconda ,same there python setup.py install.