I'm attempting to use the python 010 editor template parser
The doc specifically states (to get started):
import pfp
pfp.parse(data_file="C:\path2File\file.SWF",template_file="C:\path2File\SWFTemplate.bt")
However, it throws:
RuntimeError: Unable to invoke 'cpp'. Make sure its path was passed correctly
Original error: [Error 2] The system cannot find the file specified
I've tried everything, from using raw strings:
df = r"C:\path2File\file.swf"
tf = r"C:\path2File\SWFTemplate.bt"
To single and then double '\'s or '/'s in the string. However, it keeps throwing the above error message.
I checked the files are in the path and ensured everything is properly spelled, case sensitively.
To test my paths, I've used the windows "type" (equiv to *nix strings) and passed the strings as args in a subprocess.Popen which worked.
The problem is that it's trying to invoke a C++ compiler: cpp and you don't have one.
You'll need to install one, or make sure that your PATH has a cpp.exe on it somewhere.
Related
I followed these instructions on how to get pylint to import my files correctly using an init-hook.
However, when I run the terminal command pylint server.py --rcfile=../.pylintrc I get TypeError: expected str, bytes or os.PathLike object, not NoneType. (I assume this is because the part of the init-hook that finds the rcfile is somehow failing, but I'm not sure.)
Here's my .pylintrc file up to the relevant parts (the rest is just the default template):
[MASTER]
# A comma-separated list of package or module names from where C extensions may
# be loaded. Extensions are loading into the active Python interpreter and may
# run arbitrary code.
extension-pkg-whitelist=
# Specify a score threshold to be exceeded before program exits with error.
fail-under=10.0
# Add files or directories to the blacklist. They should be base names, not
# paths.
ignore=CVS
# Add files or directories matching the regex patterns to the blacklist. The
# regex matches against base names, not paths.
ignore-patterns=
# Python code to execute, usually for sys.path manipulation such as
# pygtk.require().
# THIS GIVES THE ERROR
init-hook="from pylint.config import find_pylintrc; import os, sys; sys.path.append(os.path.dirname(find_pylintrc()))"
# THIS GIVES THE SAME ERROR
# init-hook="import os, sys, pylint; sys.path.append(os.path.join(os.path.dirname(pylint.config.PYLINTRC), 'platform'))"
How can I get this init-hook code working correctly?
I am having trouble opening an image with the neural_style script found here. When passing arguments to the script in Spyder's IPython console, I have continually received the following error:
OSError: [Errno 22] Invalid argument:'<C:/Users/Caleb/Documents/Python_Scripts/pytorch/project1/content_images/20180727_201120.jpg>'
I have attempted changing forward slashes to backslashes, using a filepath that starts at my working directory (not including the folders above it), and eliminating the filepath from the entry (i.e. simply entering the filename). None of these fixes have solved my problem. The arguments follow the form:
python neural_style/neural_style.py eval \
--content-image </path/to/content/image> \
--model </path/to/saved/model> \
--output-image </path/to/output/image> \
--cuda 1
What amendments must I make to my arguments to no longer receive this error? I am using Windows 10 and Python 3.6.5. The arguments are read by argparse.
Please note that I used () instead of <> above, not sure how to properly use <> without deleting the interior content.
Thank you!
First of all, I am new to programming.
To run python code in an external shell window, I followed the instructions given on this page
link
My problem is that if I save the python file in any path that contains a folder name with a space, it gives me this error:
C:\Python34\python.exe: can't open file 'C:\Program': [Errno 2] No such file or directory
Does not work:
C:\Program Files\Python Code
Works:
C:\ProgramFiles\PythonCode
could someone help me fix the problem???
Here is the code:
import sublime
import sublime_plugin
import subprocess
class PythonRunCommand(sublime_plugin.WindowCommand):
def run(self):
command = 'cmd /k "C:\Python34\python.exe" %s' % sublime.active_window().active_view().file_name()
subprocess.Popen(command)
subprocess methods accept a string or a list. Passing as a string is the lazy way: just copy/paste your command line and it works. That is for hardcoded commands, but things get complicated when you introduce parameters known at run-time only, which may contain spaces, etc...
Passing a list is better because you don't need to compose your command and escape spaces by yourself. Pass the parameters as a list so it's done automatically and better that you could do:
command = ['cmd','/k',r"C:\Python34\python.exe",sublime.active_window().active_view().file_name()]
And always use raw strings (r prefix) when passing literal windows paths or you may have some surprises with escape sequences meaning something (linefeed, tab, unicode...)
In this particular case, if file associations are properly set, you only need to pass the python script without any other command prefix:
command = [sublime.active_window().active_view().file_name()]
(you'll need shell=True added to the subprocess command but it's worth it because it avoids to hardcode python path, and makes your plugin portable)
I wanted to play a .wav file, without using external modules, and i read i could do that using this:
def play(audio_file_path):
subprocess.call(["ffplay", "-nodisp", "-autoexit", /Users/me/Downloads/sample.wav])
I however get:
SyntaxError: invalid syntax
If i use os.path.realpath to get the absolute path of the file, i get just the same thing. (The path i see at get info)
Environment is OSX, Python 2.7
Can someone tell me what i am doing wrong? I am new to Python (and to Programming).
There are multiple problems.
Indentation
Code inside the function should be indented, to show that it is part of the function
File name should be in a quotes
It should be a string
It should be:
def play(audio_file_path):
subprocess.call(["ffplay", "-nodisp", "-autoexit", "/Users/me/Downloads/sample.wav"])
I am working on a python script that installs an 802.1x certificate on a Windows 8.1 machine. This script works fine on Windows 8 and Windows XP (haven't tried it on other machines).
I have isolated the issue. It has to do with clearing out the folder
"C:\Windows\system32\config\systemprofile\AppData\LocalLow\Microsoft\CryptURLCache\Content"
The problem is that I am using the module os and the command listdir on this folder to delete each file in it. However, listdir errors, saying the folder does not exist, when it does indeed exist.
The issue seems to be that os.listdir cannot see the LocalLow folder. If I make a two line script:
import os
os.listdir("C:\Windows\System32\config\systemprofile\AppData")
It shows the following result:
['Local', 'Roaming']
As you can see, LocalLow is missing.
I thought it might be a permissions issue, but I am having serious trouble figuring out what a next step might be. I am running the process as an administrator from the command line, and it simply doesn't see the folder.
Thanks in advance!
Edit: changing the string to r"C:\Windows\System32\config\systemprofile\AppData", "C:\Windows\System32\config\systemprofile\AppData", or C:/Windows/System32/config/systemprofile/AppData" all produce identical results
Edit: Another unusual wrinkle in this issue: If I manually create a new directory in that location I am unable to see it through os.listdir either. In addition, I cannot browse to the LocalLow or my New Folder through the "Save As.." command in Notepad++
I'm starting to think this is a bug in Windows 8.1 preview.
I encountered this issue recently.
I found it's caused by Windows file system redirector
and you can check out following python snippet
import ctypes
class disable_file_system_redirection:
_disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
_revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
def __enter__(self):
self.old_value = ctypes.c_long()
self.success = self._disable(ctypes.byref(self.old_value))
def __exit__(self, type, value, traceback):
if self.success:
self._revert(self.old_value)
#Example usage
import os
path = 'C:\\Windows\\System32\\config\\systemprofile\\AppData'
print os.listdir(path)
with disable_file_system_redirection():
print os.listdir(path)
print os.listdir(path)
ref : http://code.activestate.com/recipes/578035-disable-file-system-redirector/
You must have escape sequences in your path. You should use a raw string for file/directory paths:
# By putting the 'r' at the start, I make this string a raw string
# Raw strings do not process escape sequences
r"C:\path\to\file"
or put the slashes the other way:
"C:/path/to/file"
or escape the slashes:
# You probably won't want this method because it makes your paths huge
# I just listed it because it *does* work
"C:\\path\\to\\file"
I'm curious as to how you are able to list the contents with those two lines. You are using escape sequences \W, \S, \c, \s, \A in your code. Try escaping the back slash like this:
import os
os.listdir('C:\\Windows\\System32\\config\\systemprofile\\AppData')