Python Forum
[split] Help- converting file with pyton script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[split] Help- converting file with pyton script
#1
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?
buran write Jul-01-2021, 02:32 PM:
Please, use proper tags when post code, traceback, output, etc.
See BBcode help for more info.
Also don't hijack threads.
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(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"
Reply
#4
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.
Reply
#5
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
Reply
#6
(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.
Reply
#7
(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.
eltomassito likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting .txt to .csv file SunWers 21 11,718 Jan-20-2024, 10:03 AM
Last Post: Larz60+
  How to "tee" (=split) output to screen and into file? pstein 6 1,290 Jun-24-2023, 08:00 AM
Last Post: Gribouillis
  Split pdf in pypdf based upon file regex standenman 1 1,974 Feb-03-2023, 12:01 PM
Last Post: SpongeB0B
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,170 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  How to split file by same values from column from imported CSV file? Paqqno 5 2,705 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  [split] Results of this program in an excel file eisamabodian 1 1,543 Feb-11-2022, 03:18 PM
Last Post: snippsat
  split txt file data on the first column value shantanu97 2 2,379 Dec-29-2021, 05:03 PM
Last Post: DeaD_EyE
  Split Characters As Lines in File quest_ 3 2,470 Dec-28-2020, 09:31 AM
Last Post: quest_
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,255 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  Help- converting file with pyton script grinleon 3 2,440 Sep-23-2020, 11:48 AM
Last Post: grinleon

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020