adityarathod / pyandoc

Python wrapper for Pandoc—the universal document converter.
https://pypi.python.org/pypi/pyandoc/
MIT License
213 stars 32 forks source link

windows error #5

Closed Alquimista closed 8 years ago

Alquimista commented 12 years ago

file "c:\users\calcon\desktop\src\pyandoc\pandoc\core.py", line 35, in (lambda x, fmt=fmt: cls._output(x, fmt)), # fget File "c:\users\calcon\desktop\src\pyandoc\pandoc\core.py", line 48, in _output stdout=subprocess.PIPE File "C:\Python27\lib\subprocess.py", line 679, in init errread, errwrite) File "C:\Python27\lib\subprocess.py", line 896, in _execute_child startupinfo) WindowsError: [Error 2] El sistema no puede encontrar el archivo especificado

yoavram commented 12 years ago

Same here:


---------------------------------------------------------------------------
WindowsError                              Traceback (most recent call last)
<ipython-input-14-cd7911670ee8> in <module>()
      1 doc.markdown = text
----> 2 print doc.html

C:\Python27\lib\site-packages\pandoc\core.pyc in <lambda>(x, fmt)
     33                         clean_fmt = fmt.replace('+', '_')
     34             setattr(cls, clean_fmt, property(
---> 35                                 (lambda x, fmt=fmt: cls._output(x, fmt)), # fget
     36                 (lambda x, y, fmt=fmt: cls._input(x, y, fmt)))) # fset
     37 

C:\Python27\lib\site-packages\pandoc\core.pyc in _output(self, format)
     46                         [PANDOC_PATH, '--from=%s' % self._format, '--to=%s' % format],
     47                         stdin=subprocess.PIPE,
---> 48                         stdout=subprocess.PIPE
     49         )
     50 

C:\Python27\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
    677                             p2cread, p2cwrite,
    678                             c2pread, c2pwrite,
--> 679                             errread, errwrite)
    680 
    681         if mswindows:

C:\Python27\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
    894                                          env,
    895                                          cwd,
--> 896                                          startupinfo)
    897             except pywintypes.error, e:
    898                 # Translate pywintypes.error to WindowsError, which is

WindowsError: [Error 2] The system cannot find the file specified

Although pandoc exists and:

os.path.exists(pandoc.PANDOC_PATH)

returns True.

yoavram commented 12 years ago

I think I found the problem. I changed core.py:

def _output(self, format):
        # print format
        import os.path
        print PANDOC_PATH, os.path.exists(PANDOC_PATH)
        p = subprocess.Popen(
            [PANDOC_PATH, '--from=%s' % self._format, '--to=%s' % format],
            stdin=subprocess.PIPE, 
            stdout=subprocess.PIPE
        )

        return p.communicate(self._content)[0]

And now when I run

import pandoc
pandoc.PANDOC_PATH = r'C:\Program Files (x86)\Pandoc\bin\pandoc.exe'
doc = pandoc.Document()
doc.markdown = "Hello Wordl!"
print doc.html

I get a print (before the WindowsError: [Error 2] The system cannot find the file specified)

/Users/kreitz/.cabal/bin//pandoc False
OiNutter commented 11 years ago

As a quick fix until @kennethreitz (hopefully) approves my changes, if you do pandoc.core.PANDOC_PATH = 'pandoc', that will work

yoavram commented 11 years ago

I did the same change in my own Pull Request which also adds support for writing PDF and ePUB. Although my Pull Request doesn't have a set_path function.

OiNutter commented 11 years ago

Did setting pandoc.PANDOC_PATH actually work correctly for you? Didn't seem to make any difference when I did it, hence the set_path function.

yoavram commented 11 years ago

It didn't, so I changed the code to PANDOC_PATH = 'pandoc' like you did...

OiNutter commented 11 years ago

Right, with you, so if anyone needs to change it, it won't work, but the default will work out of the box. I'll leave my Pull Request in for now then, as the set_path sounds like it's still necessary. Sorry for overlapping, hadn't seen that part of your Pull Request.

yoavram commented 11 years ago

No problem at all! It is necessary. If you want you can also do a pull-request on my repo and I'll merge it to my pull-request #6, it will save @kennethreitz some work.

OiNutter commented 11 years ago

Done

kennethreitz commented 8 years ago

This should now be fixed!

AnshumanMisra007 commented 6 years ago

Build mongoimport command

collection = OSM_FILE[:OSM_FILE.find('.')] working_directory = '/Users/Anshuman Misra/Downloads/' json_file = OSM_FILE + '.json'

mongoimport_cmd = 'mongoimport -h 127.0.0.1:27017 ' + \ '--db ' + db_name + \ ' --collection ' + collection + \ ' --file ' + working_directory + json_file

Before importing, drop collection if it exists (i.e. a re-run)

if collection in db.collection_names(): print 'Dropping collection: ' + collection db[collection].drop()

Execute the command

print 'Executing: ' + mongoimport_cmd subprocess.call(mongoimport_cmd.split()) on running this WindowsErrorTraceback (most recent call last)

in () 13 # Execute the command 14 print 'Executing: ' + mongoimport_cmd ---> 15 subprocess.call(mongoimport_cmd.split()) C:\Users\Anshuman Misra\Downloads\Anaconda2\lib\subprocess.pyc in call(*popenargs, **kwargs) 166 retcode = call(["ls", "-l"]) 167 """ --> 168 return Popen(*popenargs, **kwargs).wait() 169 170 C:\Users\Anshuman Misra\Downloads\Anaconda2\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags) 388 p2cread, p2cwrite, 389 c2pread, c2pwrite, --> 390 errread, errwrite) 391 except Exception: 392 # Preserve original exception in case os.close raises. C:\Users\Anshuman Misra\Downloads\Anaconda2\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite) 638 env, 639 cwd, --> 640 startupinfo) 641 except pywintypes.error, e: 642 # Translate pywintypes.error to WindowsError, which is WindowsError: [Error 2] The system cannot find the file specified