Why does gitpython on windows always get file not found errors? - python

When looking at the tutorial located here for gitpython, and following step by step there are some issues on my machine. The environment is Windows 7, and git version 1.7.11.msysgit.1 along with Python 2.7. Everything installed fine with easy_install. Repo object successfully gets created, and commands like repo.tree() and repo.branches work. If I do a repo.is_dirty() there are non-specific file not found errors. WindowsError: [Error 2] The system cannot find the file specified. Any ideas?
path = "c:\\path_to_repo"
repo = Repo(path)
assert repo.bare == False
print repo.tree()
repo.branches
print dir(repo)
#these always crash...
repo.is_dirty()
TIA for any help.

You might not have git.ext in your PATH, but that can easily be tested by executing it yourself. If you see an error, you can either add it to the PATH, or set the GIT_PYTHON_GIT_EXECUTABLE to the executable that git-python should execute for git command line services.
The reason it works for .tree() and related object queries is that gitpython uses a pure-python backend for these operations. More complex operations like .is_dirty() still require the git executable to be in your PATH by default.

Related

Python script installation fails on windows

I'm trying to deploy a larger python project which includes a script on
windows. Installation works fine on UNIX, but on windows it seems
impossible to get the script running. I've created a minimal example on
GitHub to demonstrate
the problem.
When running pip install ., the script is installed to C:\Program Files\Python39\Scripts\hello-world. The directory is contained in the
PATH. My user has read & execute permissions. The hashbang of
hello-world is replaced with #!c:\program files\python39\python.exe,
which also seems correct. However, running hello-world in the console
yields the following error:
C:\Users\malte>hello-world
'hello-world' is not recognized as an internal or external command,
operable program or batch file.
I expected this to work. Why doesn't it? How can I fix this?
I've tried some things, and noticed another strange behavior in this
context. Running shutil.which('hello-world') returns None. If I
rename hello-world to hello-world.exe, then calling hello-world
results in a strange error, most likely because windows
now thinks the script is a binary. That's fine. Except that now
shutil.which('hello-world')
returns 'C:\\Program Files\\Python39\\Scripts\\hello-world.EXE'. Why?
Update
The master branch of the respository now contains a solution that works cross-platform, which I learned from here: https://matthew-brett.github.io/pydagogue/installing_scripts.html.
It's not exactly clear to me, but the following paragraph from the Python documentation seems to state that a script with a hashbang line must have an extension associated with the python launcher in order for windows to recognize it: https://docs.python.org/3/using/windows.html#from-a-script
In other words, it appears that my assumption that using the scripts parameter of setuptools.setup works cross-platform is subject to some conditions which are hidden somewhere in the python documentation.

Bundle pdflatex to run on an AWS Lambda with a custom AMI image

My goal is to create an Amazon Lambda Function to compile .tex files into .pdf using the pdflatex tool through python.
I've built an EC2 instance using Amazon's AMI and installed pdflatex using yum:
yum install texlive-collection-latex.noarch
This way, I can use the pdflatex and my python code works, compiling my .tex into a .pdf the way I want.
Now, I need to create a .zip file bundle containing the pdflatex tool; latexcodec (a python library I've used, no problem with this one); and my python files: handler (lambda function handler) and worker (which compiles my .tex file).
This bundle is the deployment package needed to upload my code and libraries to Amazon Lambda.
The problem is: pdflatex has a lot of dependencies, and I'd have to gather everything in one place. I've found a script which does that for me:
http://www.metashock.de/2012/11/export-binary-with-lib-dependencies/
I've set my PATH to find the pdflatex binary at the new directory so I can use it and I had an issue: pdflatex couldn't find some dependencies. I was able to fix it by setting an environment variable to the folder where the script moved everything to:
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/home/ec2-user/lambda/local/lib64:/home/ec2-user/lambda/local/usr/lib64"
At this point, I was running pdflatex directly, through bash. But my python script was firing an error when trying to use the pdflatex:
mktexfmt: No such file or directory
I can't find the format file `pdflatex.fmt'!
I was also able to solve this by moving the pdflatex.fmt and texmf.cnf files to my bundle folder and setting some environment variables as well:
export TEXFORMATS=/home/ec2-user/lambda/local/usr/bin
And now, my current problem, the python script keeps throwing the following error:
---! /home/ec2-user/lambda/local/usr/bin/pdflatex.fmt doesn't match pdftex.pool
(Fatal format file error; I'm stymied)
I've found some possible solutions; deleting a .texmf-var folder, which in my case, does not exist; using fmtutil, which I don't have in my AMI image...
1 - Was I missing any environment variable?
2 - Or moving my pdflatex binary and all its dependencies the wrong way?
3 - Is there any correct way to move a binary and all its dependencies so it can be used in other machine (considering the env variables)?
Lambda environment is a container and not a common EC2 Instance. All files in your .zip is deployed in /var/task/ inside the container. By the way, everything is mounted as read-only, except the directory /tmp. So, it's impossible to run a yum, for example.
For you case, I'd recommend you to put the binaries in your zip and invoke it in /var/task/<binary name>. Remember to put a binary compiled statically in a linux compatible with the container's kernel.
samoconnor is doing pretty much exactly what you want in https://github.com/samoconnor/lambdalatex. Note that he sets environment variables in his handler function
os.environ['PATH'] += ":/var/task/texlive/2017/bin/x86_64-linux/"
os.environ['HOME'] = "/tmp/latex/"
os.environ['PERL5LIB'] = "/var/task/texlive/2017/tlpkg/TeXLive/"
that might do the trick for you as-well.

svn: E155007: '/home/k/python/myproject_env/django-myproject/myproject' is not a working copy

I have been building django project and I want to use Subversion for version control on Ubuntu.
As you know, I need to keep most of the projects in the repository, however, some files and directories should only stay locally and not be tracked.
So I went to my project directory and typed the following command.
svn propedit svn:ignore myproject
But exception has occurred like this.
svn: E155007: '/home/k/python/myproject_env/django-myproject/myproject' is not a working copy
The path is ture that my app is located at /home/k/python/myproject_env/django-myproject/myproject
The guide says that when I type the command above, this will open a temporary file in the editor, where I need to put the following file and directory patterns for Subversion to ignore. But it doesn't work.
I already found the solution, but there is no answer anywhere.
I would like to know the solution. Thanks for your time.

Python correctly finding and reading windows application event logs

so my ultimate goal is to use python to read a specific application's windows event log when triggered by a file update.
Here is my problem, python I believe does not have access to the event logs stored in C:\Windows\System32\winevt\Logs. Whenever I try to read the files I get the following error:
WindowsError: [Error 2] The system cannot find the file specified
I tried every form of escaping, string split/join and using quotes on the file path and I always get the same error. I even cheaply used the os.system('dir "C:\Windows\System32..."') command in the python command prompt to list directories higher in the path for the log to verify access and I receive similar errors up to the C:\Windows\System32 directory, that one will list just fine.
Example:
C:\Windows\System32\winevt\Logs - File not found
C:\Windows\System32\winevt - File not found
C:\Windows\System32 - Lists files
I know these directories exist. So from here I figured I could use a bash script to copy the event log into a temp folder for python to read. I wrote a real simple bash script containing:
xcopy /Y "C:\Windows\System32\winevt\Logs\XXXXXXX" c:\Temp
(XXXXXXX) being the name of the log I want to copy for the python script.
The bash script runs fine on its own but when called by my python script it fails, refuses to copy the file because it can't find it. I have even tried using py2exe to create an exe to then run in administrator mode. This failed too. With similar errors of the file not found. I'm not sure I understand the permissions python uses to call the script and why the bash script cannot copy the file even when it can do it in a normal command prompt.
Any suggestions or flaws you can point out in my logic would be great. I am very stuck.
You are using a 32bits python on a 64bit install of windows.
In most cases, whenever a 32-bit application attempts to access %windir%\System32, the access is redirected to %windir%\SysWOW64
You can use os.listdir("c:\windows\sysnative\winevt\logs") as a workaround to read from the real system32 dir from a 32bit python interpretter runing on a 64bit windows...
Sources:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384187(v=vs.85).aspx
http://support.microsoft.com/kb/942589

Error running .py from Windows 7 command prompt

I am new to python and I have just installed python 2.7.3 on Windows. I will also install django so I need to execute a file named ez_setup.py. I know it seems like an easy question and answer can be found in internet, but this is not the case. I tried lots of things and tried what internet says, the problem is still there and I cant find the problem!
I follow all the steps that is explained in tutorials in order for Python to work properly. (Installing steps and editing environment variables..)
Python's location is:
C:\Users\name\27
Command prompt starts like:
C:\Users\name>
I have put ez_setup.py file under both C:\Users\name\27 and C:\Users\name.
When I type "ez_setup.py" or "python ez_setup.py" or "\27 python ez_setup.py" and lot of combination, it says:
python: cant open file 'ez_setup.py': [Errno 2] No such file or directory.
What should I do? Where do I make mistake?
Just do:
python ez_setup.py
You need to say your machine that it should execute this .py file with python.

Categories