Github desktop and git hooks - python

I am having an issue with implementing git hooks with the Github Desktop client for windows. When I created the hook, it runs a python script that checks the commit message. The weird part is, it runs on perfectly fine on Windows with command prompt, powershell, tortoisegit, webstorm IDE, git bash, also works on Linux terminal, EXCEPT for Github Windows client. reading the debug log, i get this error
GitHub.IO.ProcessException: /usr/bin/env: python: No such file or directory
My already attempted solutions:
adding 'python' as system variable
using ruby
removing '/usr/bin/env' (this will throw an error saying this file doesn't exists)
adding a .bashrc file solution i found online by putting the python path in my home directory
Does anyone have any idea how to fix this?

This error means that Git cannot find
To fix that, append C:\Python (or wherever you installed python) to your PATH environment variable in windows (control panel > System).
Once you set it up test the hook again.
Another option is to create a .bashrc file in your %USERPROFILE% directory and set the variable there:
export PATH=/c/Python:$PATH
Again - check to see that it fixed the problem.

Related

'Cannot setup a Python SDK' in PyCharm project using virtualenv after OS reinstallation

I re-installed windows and opened an existing Pycharm project and get the error 'SDK seems invalid' in Settings > Project Interpreter.
The project interpreter path is pointing to python in the venv:
MyProject\venv\Scripts\python.exe
I tried re-adding python.exe:
Thats when I get the error:
Update: here is an error from idea.log, a lot of other issues for virtual environments seem to be with windows environment variables and system paths:
2018-09-28 19:50:40,275 [ 17601] INFO - hon.packaging.PyPIPackageCache - Loaded 153296 packages from C:\Users\Matt\.PyCharm2018.2\system\python_packages\pypi-cache.json
2018-09-28 19:50:40,816 [ 18142] INFO - rains.python.sdk.PythonSdkType - Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000fa8 (most recent call first):
Exit code -1073740791
2018-09-28 19:50:40,816 [ 18142] ERROR - ns.python.sdk.PythonSdkUpdater - Failed to determine Python's sys.path value:
STDOUT:
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00000fa8 (most recent call first):
com.jetbrains.python.sdk.InvalidSdkException: Failed to determine Python's sys.path value:
STDOUT:
STDERR: Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
What solution is: Check out venv\pyvenv.cfg and provide a valid path to the basic python installation.
What has most probably happend:
After reinstalling your OS, you have no base python interpreter reinstalled or you have installed it at different location than before. Thus your virtual environment fails to locate the python installation. Virtual environment implies that all libraries and settings are isolated from other projects. It does not provide an isolated python installation. You still need your base python that had been used for venv creation.
My case: I have a project in a network share and try accessing it from different computers. The base python paths depend on the very PC. The solution above works fine for me. Unfortunatelly, I need to update pyvenv.cfg depending on the PC in use.
P.S. I believe that there is an environment variable to overide the venv config value. I only tried to set PYTHONPATH=C:\Anaconda3\envs\python37 on Windows and then to activate venv. It did no effect and I gave it up.
Here's what solved my problem when I faced the exact same issue
Navigate to Project Interpreter, right side of the selection box, click the gear icon, it will show two options add & show all.
Click show all, if you see the previous existence from the same directory delete that. Click on add or + sign to add a new interpreter and navigate to your project path, navigate down to the virtual environment directory.
venv/bin/{select the python executable with the version code i.e if you are using python3.6 select python3.6}
Once selected, you can now click the notice that says install packaging tools, hit apply and done.
Most probably, some path to Python environment that PyCharm tries to use has become invalid somewhere. There are (at least) two primary suspects:
Path to your virtualenv in PyCharm settings
PyCharm needs to know the path to your environment to run things in it. So, if that path changed, PyCharm's saved path has become invalid.
Go to the interpreter settings for your project in File->Settings...->Project interpreter->(Gear icon)->Show all...:
Then delete and recreate the necessary entries. Or edit them and specify correct paths.
E.g. this is what my list looks like after I deleted an Anaconda installation:
Path in the virtualenv to its base installation
Since virtualenv is not a full installation, it must have a path to its base installation stored somewhere to be able to use files from there.
As of this writing, virtualenv (v16.0.0) in Windows is implemented like this:
The real python.exe and several other files are copied into the virtualenv's subtree
In Lib\orig-prefix.txt, the path to the base installation is stored. It is used to add the base installation's Lib to sys.path via a custom site.py.
So, if the path in that file becomes invalid, the virtualenv's Python interpreter will be unable to find any standard modules except those few that were copied. Which perfectly fits your symptoms.
I currently have the same issue, that I can't install any package tool in Pycharm and that freak me out. Here is the step I fixed it, just want to share. OuO.
Step 1
Find show all in the right corner of a setting icon
Step 2
Click the + icon to open Add python Interpreter
Step 3
In New environment 's Location Under Virtualenv Environment select file
Step 4
Find your Pycharm file and make an empty file under it and click OK and keep click OK
Step 5
Now in Project Interpreter select the empty file you just create and now you should be fine to install Pycharm package.Hope this solve your problem.
In my case the problem was because I was using WSL to host my project so the project address used by PyCharm to create and select the venv was wrong. Instead of using the option Virtualenv Environment to create the environment:
You need to select the WSL option from the side bar and then enter the path to your new or existing venv.
Nothing above worked for me
I made a simple change , Hope it works for you too !!
It happens due to conflict in storing python.exe , In my case it was in F:\ drive
Solution :- Pycharm expects python.exe file to be present in some location , you can check that in project interpreter , it will show some default location where pycharm is searching to execute exe file , but issue is the exe file is not present at that location , so create the folder which pycharm was expecting to execute exe file and paste the downloaded exe file
Hope it Works for you !!
Happy Coding
Well, i'm pritty new to Python, and I did too had a re-install of my os after a crash
Old setup:
In the old system setup I used python 3.7.4. I made al my (practice)projects with that, and each project had a venv/scripts/python3.7.exe in it.... my undertanding is/was that all the files in these virtual environment where 'stand alone', so sufficient to run a python 3.7.4 for that specific projec files, and not depending on files of the home-python-dir.
The install-directory of python was c:\Program Files (x86)\python 37-32
Each project had a file [project-path]/venv/pyvenv.cfg, and in this file there was the line
home = C:\Program Files (x86)\Python37-32
then - my system crashed - reinstalled windows 10, and downloaded again python, but this time python 3.8, and it installed in C:\Program Files (x86)\Python38-32
New setup:
So, after some hairs lost - I also installed the old python version 3.7.4 in the specific path stated in the pyenv.cfg file (C:\Program Files (x86)\Python37-32). So, i had 2 python versions installed on my new system, one in .../python38-32 and one in .../python37-32
And that worked, so when I selected in 'add interpreter/existing interpreter' and pointed to the [project]/venv/python3.7.exe it worked like a charm.
So, apearantly there are files in each version-specific home-directory that pycharm/python needs - i was under the impression that the files in the .venv directory would be all it needed....
I faced this issue when I switched my system which had different python version installed at different location. The simple short solution is to open 'pyenv' file and point it to the current installation path in your current system and that's it.
I had the same problem and couldn't really figure it out.
As it was a side project the mistake was infuriating and hilarious at the same time.
My folder names had non-english letters. Specifically it had the letter "đ" and the SDK was always invalid because of it.
You might say a stupid mistake, it was, but I wasn't really paying attention.
Hope this helps somebody.
I get the issue in Pycharm 2021.2.3 when I try to make a new environment using an exe that is called anything but python.exe (I was organising my different versions by calling them python39.exe, python38.exe, etc.). I just stopped doing that and renamed all my python exes to python.exe and it started working.
go to the Edit Configuration foe edit interpreter, then remove all interpreter then ok.
now, you should add new interpreter and select the path of python.exe in your installation path(for example c:\ ),then ok.
for me, i solved this error by this solution.
The paths specified in pyvenv.cfg need to be corrected after the venv folder is copied from one computer to another. The main place to look at is the user name. For example:
Old computer:C:\Users\OldComputerUserName\AppData\Local\Programs\Python\Python310
New computer:C:\Users\NewComputerUserName\AppData\Local\Programs\Python\Python310
The path is fixed when you add interpreter to the project the 1st time. I learned it the hard way too.
This problem is because the interpreter path points to the virtual-env, instantiated to the particular project. But we don't have any python installed there.
Therefore we have to set the interpreter path to the "python.exe" file inside the python folder which we have installed on our PC.
This can solve this problem very easily.
If you haven't installed python on your machine please install it and set the path accordingly.
Thank you.
I also had this issue and it's 2023! All I can tell you is what I did to fix it. I tried the other solutions listed in this post (at least the ones I looked at) and they didn't work.
What I did was I copied the venv file in my project (for safekeeping) and then moved it elsewhere.
I deleted the venv file in my project after making my backup and I deleted the interpreter that I had been trying to use.
From there I opened up File -> Settings -> Python Interpreter -> and since there was now no interpreter and no venv folder
I created the interpreter again. Make sure to list the proper path to the version of the python exe you want to use!
From there you pretty much just apply your changes and you will see it pop up with some prompts. It will create a new venv folder for you, just accept the prompts and it worked for me.

Python where do I run this from?

I'm trying to use clarifai with python, I've installed the package using pip, but then it says (here) to get started by configuration as follows.
Configuration
The client uses CLARIFAI_APP_ID and CLARIFAI_APP_SECRET for authentication and token generation. You can get those values from https://developer.clarifai.com and then run:
$ clarifai config
CLARIFAI_APP_ID: []: ************************************YQEd
CLARIFAI_APP_SECRET: []: ************************************gCqT
The config will be stored under ~/.clarifai/config for client's use
But I do not understand where I "run" this from and do i need the "$". I've tried running it from python command prompt and windows command terminal but it just gives errors.
I have a Python27/scripts folder, in this I have a file caled 'clarifai' but with unknow extension i.e. I dont know if its a .py file or .exe file, I have no idea. If I open that file in notepad it reads
""" the clarifai command line utility,
Basically it helps to setup the environmental variables for the
API Clients """
So this is exactly what I want to do set the 'environmental variables' CLARIFAI_APP_ID: and CLARIFAI_APP_SECRET: but i have no idea how to do this. I tried to run this in the windows command terminal and in the python terminal but get errors both times.
someone suggested below "You should probably run in the folder you installed it to". But I did not install this, pip installed this I I dont understand where it installed it to?
Where should do you think they are implying I run this from?
You do not need the $. You should probably run in the folder you installed it to, provided you didn't add to %PATH% yet. If you did, anywhere should be fine. Windows CMD or PowerShell is probably what they want.

os.system does not look the programs that are in my path

I have a problem when calling programs inside a python script. The programs that are giving me problems are those that I have installed manually on my computer and then added them to path on .bashrc file. The programs that where installed using 'sudo apt-get install some_program' don't give me any problem
The programs where added to my .bashrc file as the following way:
#path to fastqc
export PATH=$PATH:/home/bioinfor3/bin/FastQC/
#path to fastx-toolkits
export PATH=$PATH:/home/bioinfor3/bin/fastx/
Inside my PyCharm, I am using the os module to call those programs the in the below manner:
os.system('fastqc seq.fastq')
And I get this error
sh: 1: fastqc: not found
I guess it has something to do with the sh path or something, but I am not able to make it work
EDIT:
If Pycharm is launched from the terminal, it inherits the bashrc file with my personal paths and it works
Presumably this is happening because you have modified your login environment to adjust your PATH, but this updated path isn't seen by the shell that's running PyCharm, or PyCharm appears to be nullifying it somehow.
You should first of all verify that
os.system('/home/bioinfor3/bin/FastQC/fastqc seq.fastq')
operates as you would expect (no reason why it shouldn't, but worth checking).
It seems from this answer that by default PyCharm doesn't use bash for its shell but tcsh. Therefore it isn't seeing the setting you are enforcing on bash.

appcfg.py command not found

I am following the How to set up AppEngineBackend Tutorial on this website https://cloud.google.com/resources/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial
My current environment is:
1.Windows 8(64-bit).
2.Java 7
3.Eclipse 4.2 with ADT(Its the eclipse that is preconfigured with ADT downloaded from the Android Website)
I have had many problems relating to Java, invalid AppEngine SDK, etc. ever since I have started this tutorial. I resolved many of them and have come to the point where data needs to be uploaded to AppEngine datastore from a .csv file using a script in an upload_data.sh file using the following command :
./upload_data.sh places.csv Place
The contents of upload_data.sh are:
!/bin/sh
appcfg.py upload_data
--config_file bulkloader.yaml --url="http://localhost:8888/remote_api" --filename $1 --kind=$2 -e
nobody#nowhere.com
Now the problem is that Windows does not support the .sh files. Also the file contains commands such as appcfg.py, --config_file,etc. For running the .sh file I downloaded Cygwin. Then I installed Python33 and also set the PythonPath environment variable to c:\python33. When I run the above command from Cygwin terminal I get the following:
./upload_data.sh: line 2: appcfg.py: command not found
./upload_data.sh: line 3: --config_file: command not found
./upload_data.sh: line 4: nobody#nowhere.com: command not found
Do I need to tell Cygwin about my python location ? If yes then how to do it?
Also I installed Python and Cygwin much later after I installed Google AppEngine SDK.Is this causing the problem?Are Cygwin and Python supposed to be installed before AppEngine SDK?Does installation of AppEngine SDK automatically inform Cygwin about appcfg.py,etc.?
Although it's not listed as a prerequisite, installing the Google App Engine SDK for Python (available at Google's App Engine SDK Download page) makes appcfg.py available to the command line.
During the installation of this SDK on a Mac, the installation puts appcfg.py on the PATH, thereby solving the "appcfg.py: command not found" error message. This may be similar for Windows.
Additionally, remove the line breaks (i.e., the "Next line" space) that occurs before the --config_file and nobody#nowhere.com words - the script only needs to be a single continuous line without any line breaks (the line should only overflow to the next line due to reaching the edge of the editor).
Here is a simple work around.There's no need to create a shell or .bat file. This should work for anyone and for any operating system using the terminal or command prompt. Your local server should be running in debug mode or in other words you can successfully navigate to http://localhost:8888/_ah/admin
Make sure you have downloaded and extracted Google App Engine SDK for Python to any location on your computer because the appcfg.py file is located in the parent directory extracted.
Put the following files "bulkloader.yaml and places.csv" in the parent folder extracted in step1 i.e. in the same directory where the appcfg.py file is located.
Run the following command directly in the terminal or command prompt:
python appcfg.py upload_data --config_file bulkloader.yaml --url=http://localhost:8888/remote_api --filename places.csv --kind=Place -e nobody#nowhere.com
Press enter when password prompt appears.. Enjoy!!!. Also you might need to wait for about a minute or two sometimes to confirm if the data is available from the datastore viewer.
The simplest solution (in my mind) to your question is to create a .bat file with following content:
python appcfg.py upload_data --config_file bulkloader.yaml --url="http://localhost:8888/remote_api" --filename $1 --kind=$2 -e nobody#nowhere.com
I haven't tested it so it might not work. Don't have a windows machine now. You'll need to put the folder of python.exe in your PATH environment variable.
Please use python 2.7 instead of python 3.3. I'm pretty sure Google App Engine doesn't support any Python 3.x yet.
Cheers
I also got this error on my Mac. It seems the newest version of Google App Engine not include appcfg.py in $PATH by default. The directory includes appcfg.py on my mac is $HOME/google-cloud-sdk/platform/google_appengine/, you can just add this directory in your $PATH and it should work.
If the reason you are searching for this fix is to error in appengine deployment since it states that another deploy is in progress and your app is built with maven, the easier way to rollback is to point your terminal to the directory from where you run the appengine deployments, and type $appengine:rollback.
I know the question is far from the past, but pay attention that appcfg.py is deprecated
Now you should use gcloud commands - https://cloud.google.com/appengine/docs/standard/java/tools/migrating-from-appcfg-to-gcloud

Can't open file 'django-admin.py': [Errno 2] No such file or directory

I'm using Python 2.7, Django 1.2.5 and on Windows 7.
I am not sure what I've done. I used to be able to create Django projects like
python django-admin.py startproject test
Now however I get this error.
Can't open file 'django-admin.py':
[Errno 2] No such file or directory
I can type the following which works.
python C:\Python27\Scripts\django-admin.py startproject test
How can I have it the way it used to be? Not having the type the full path to the django-admin.py file.
Things I've already tried:
I uninstalled Python and manually removed the values from the PATH variable in Windows. Reinstalled Python. Deleted Django and reinstalled it too.
I've added C:\Python27\Scripts to my PATH and PYTHONPATH variable under Environmental Variables in Windows.
Any suggestions?
My PATH variable contains
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files (x86)\ActiveState Komodo Edit 6\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\django-apps;F:\My_Projects;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Mercurial\bin;C:\Python27;C:\Python27\Scripts
PYTHONPATH has
C:\Python27;C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\Python27\Scripts;C:\django-apps;f:\my_projects
I had this same problem with slightly newer versions of Python 2.7.x and Django - and it is not the PATH. This is all I had to do to fix it in Windows XP:
Find a .py file (any, even a blank).
Right click on it and choose: "Open with>" and then select "Choose program...".
This pops up a list of all programs - select python, and check the box "Always use the selected program to open this kind of file" and then click OK.
Checking this box resets file associations and fixes this problem for the command line.
The cause of the problem: Telling Windows to open up .py files in a text editor as default.
If C:\Python27\Scripts is in your Path, just type in:
django-admin.py startproject proj
There should be a file association with .py and try to execute. If you prefix with python the next command is a file path.
I've never been able to do python django-admin.py -- I get the same error you describe.
Make sure python is associated with .py. You can check via file properties (opens with...) or typing assoc .py in cmd.
Here is what I did to get this working:
Installed Python 2.7 to C:\Python27 using the install package for Windows at python.org
I chose to install the latest release version of Django (1.3) (not the development trunk)
Installed Django following the instructions here: http://docs.djangoproject.com/en/dev/topics/install/
I'm only doing local development, so I skipped install of Apache and mod_wsgi (as directed in Django instructions)
I don't need a database for my app, so I skipped "Get your database running" section in Django instructions; and I skipped "Remove any old versions of Django" (didn't have any installed)
I skipped down the instructions to "Installing an official release"
I installed bsdtar as directed in order to untar the release files on my windows machine - ran no problem.
Being on Windows, I started a cmd shell with admin privileges and ran the command "setup.py install" - ran no problem
I followed the instruction to verify Django install: running import django and django.print get_version() - returned 1.3, success
Then it came time to run django-admin.py startproject myproject - I received similar errors to the above, and when trying to run django-admin.py from within the python interpreter, I received syntax errors pointing at the arguments. Strange.
Found this thread, and ran this, which worked: c:\Python27\Scripts\django-admin.py startproject myproject and it worked.
Still curious, I wanted to see if I could make it work from cmd prompt, without the paths, since it seemed that should work - and it didn't.
This is what I did beyond the install instructions that made it work for me on Windows:
Verified the file associations, using info from this post - all associations good.
Used Start|Computer|System Properties|Advanced System Properties|Environment Variables dialog to set the environment variables as follows:
Set New System Variable: PYTHONPATH = c:\Python27\Lib;c:\Python27\Scripts
Edit existing User variable: PATH added: C:\Python27;C:\Python27\Scripts to the end.
The result:
.py files now execute from cmd command line (no need to run python interpreter first)
e.g. the command django-admin.py startproject mynewproject ran just fine.
Please post any questions in the comments, maybe I can help.
Is it possible you associated your .py files with another program (like a text editor)? I had this problem, too, after associating .py files with gedit.
I'd have the problem if I did this:
python django-admin.py startproject myproject
Once I reassociated .py files to python this problem went away.
Gosh! It drove me crazy! Just do the following!
python C:\python27\scripts\django-admin.py startproject mysite
The problem seems to be with the file association. After adding the PATH variables, remove all "py" associations instead of linking them to your Python executable:
Remove the file type ".py " from the registry or by using a small
free tool for Windows Vista/Windows 7 called 'Unassoc' (google for Windows 7 unassoc).
In my case simply unassociating the file type was not enough. I had to remove the file type entirely using the unassoc tool.
Now you should be good to go.
I've solved it! It's the command line to open a file .py.
It has to be like so:
"C:\Python27\python.exe" "%1" %*
mine was:
"C:\Python27\python.exe" "%1" without the final %*
I've used FileTypesMan to edit because Windows 7 can't edit this property.
In my case it was solved by adding the path to django-admin.py.
The instruction in windows with a python 7 and django 1.11 is:
python c:\Python27\Lib\site-packages\django\bin\django-admin.py startproject mysite
First, set the path in PowerShell (in your $profile) like this:
$env:PATH = "C:\Python27\;C:\Python27\Scripts;c:\python27\lib\site-packages\django\bin\;"
Then, to get .py files to open in PowerShell rather than cmd, add this line:
$env:PATHEXT += ";.py"
Finally, to be able to just type "django-admin" and have it work, add this line:
function django-admin {python (gcm django-admin.py | resolve-path) $args}
That should do the trick.
After I installed an IDE, I had a similar (if not the same) problem. Sure enough, the .py "Open With" setting had been changed, and changing it back to the Python Launcher for Windows did the trick.
On Windows, I used
django-admin startproject test
and it seemed to have worked.
Since the path is too long, I moved the folders to a shorter path inside C: /. This way I call it faster, there is a problem with the route. I use Windows 10 with Django 3.0.5, so it turns out like this: python C:\Python38\Scripts\django-admin.py startproject test
The problem for me was the installation of Visual Studio.
I tried to install django-admin, which is usely automatically set up:
pip3 install django-admin
and it gave to me :
error: Microsoft Visual C++ 14.0 or greater is required.
So, I install Microsoft Visual Studio, and then it works.
Make sure that you cd is where you saved your Notepad++ Python file. If you saved it under your \Python27\ directory, then while in the terminal or PowerShell window, type cd C:\Python27 and press enter.
This will open that directory so when you type python filename.py it will find it and run it. Just remember to save all .py files to the same directory, so you have no further problems.
No Windows, usei:
python -m django startproject mysite

Categories