How to execute Kaggle Api commands on windows system? - python

I'm referring to https://github.com/Kaggle/kaggle-api
I tried executing the sample commands listed on the page in windows CMD and Python's IDLE. Not sure where it should be executed or how can I go to Kaggle CLI?
Eg. command: kaggle datasets list -s demographics
Windows CMD says: 'kaggle' is not recognized as an internal or external command,
operable program or batch file.

Assuming the Kaggle API has been successfully installed using pip and the python install location along with the location of the Scripts\ folder have been added into the PATH; the execution of kaggle directly within Windows command prompt (CMD) should be able.
In order to ensure Python and the folder Scripts\ have been added into the PATH execute the command WHERE python3 succeeding WHERE kaggle.
If any of the two commands above produce an equivalent output of INFO: Could not find files for the given pattern(s) manually modify the PATH using the directions in Excursus: Setting environment variables to add both python install location and location of the Scripts\ folder.

You can run Bash commands on Windows using the Bash shell, which is a little tricky to launch the first time. You can find instructions on how to do that here: https://www.windowscentral.com/how-install-bash-shell-command-line-windows-10
Hope that helps! :)

Related

Automatically execute Sphinx on Python script using Jenkins

I have been trying to create a Jenkins job that automatically executes a python script and launch its documentation via Sphinx.
The execution part works well but I'm not able to do the Sphinx part. My first idea was to create an 'Execute Windows Script bash' step inside the Jenkins job with make html command after going to the right directory with cd. But I keep on getting this error:
make is not recognized as an internal or external command
Same idea works when I do it from the CMD tool.
I already added the PATH variable in Jenkins settings with System32 folder.
System Information:
OS: Windows
Arch: x64
I figured out, I just had to put the following inside my Windows Shell Job:
call "Path\To\make.bat"

Can't run python scripts in Jenkins

I have been using Jenkins for a few years and recently bought a new Windows 10 PC. I installed Jenkins 2.89.2, Visual Studio 2017 and Python 3.6 and copied several Jenkins jobs from my previous Windows 7 PC.
The problem that I encountered was that all the python scripts in the free-style Jenkins jobs now do nothing.
I have similar command-line batch files which run these python scripts which work just fine in a command window on the new PC.
I have also checked the file associations with ftype, and ended up changing it:
ftype Python.File
Python.File="D:\Python36_64\python.exe" "%L" %*
My work-around is like this:
Example line which worked under Windows 7:
CreateBuildNumber.py <= uses PATH to find this file, then file associations to run python
Replacement line need to work under Windows 10:
python .\Scripts\CreateBuildNumber.py <= uses PATH to find python.
How can I avoid explicit paths in my scripts?
Update:
D:\project>assoc | findstr -i python
.py=Python.File
.pyc=Python.CompiledFile
.pyd=Python.Extension
.pyo=Python.CompiledFile
.pyw=Python.NoConFile
.pyz=Python.ArchiveFile
.pyzw=Python.NoConArchiveFile
echo %PATH%
D:\Python36_64;D:\Python36_64\Scripts;.\Scripts;"C:\Program Files\CppCheck";C:\windows\system32
Further Info
I removed .\Scripts from the %PATH% and re-ran the job, having also moved demo.py into .\Scripts, now instead of doing nothing there is the error:
'demo.py' is not recognized as an internal or external command, operable program or batch file.
This means that Windows IS looking for and finding python scripts, but is failing to execute them. Why would windows not take the next step and use file associations to find an executable program to run, taking the file as a parameter?
Update:
Now everything works as it should and I don't know why.
I recently started using a different job on Jenkins that I had neither run nor touched for over two years and that one just worked without modification. I have since gone back over the job in question and reverted all the changes and this one works as well.
My guess is that Windows 10 has been patched.
The fact that "demo.py" gives the message '...is not recognized as an internal or external command' doesn't convince me that your script is recognized as executable. If I type 'turkey.abc' into a command prompt window I get the same error, and I don't have a tool for executing '.abc' files.
I see two possibilities here:
1) In batch scripts, executable extensions sometimes must appear in an environment variable called PATHEXT.
In the Jenkins batch script, add a "set" command near the top of the script to dump the environment variables for your running script into your Jenkins build log (you can remove the set command after this is debugged). Run the build. Look not only for the definition of PATH, but also at PATHEXT. Is ".py" one of the extensions listed there?
I have experienced this problem with Perl scripts. However, I'm wimping out on claiming this definitely since in testing on my Windows 10 home PC I am successfully executing .py scripts even without it being in PATHEXT, so it's something to try but it may not be this.
2) Another possibility is that the environment in which your service is running is different than the environment you get when you open a command prompt on your desktop (because the Jenkins service runs as a different user than the one you log in as.)
Adding "set" to your Jenkins batch commands will help debugging this too, since it will show you the environment your Jenkins script is running in. Then you can examine PATH to see if your script folder is being found.
It is also possible that the file associations for Python were installed for your user only, not for all users (i.e., in HKEY_CURRENT_USER in the registry instead of HKEY_LOCAL_MACHINE). That is harder to dump into your Jenkins log - the 'reg' command would do it, but it will take you a number of tries to get everything you need. You might be able to figure it out by just examining the registry. Search for ".py" - if it occurs in HKEY_LOCAL_MACHINE that is not it; if it occurs in HKEY_CURRENT_USER that is at least part of the problem.
I don't know if this will fix your issue but you shouldn't have a relative path in your PATH environment variable.
Can you try again after having removing .\Scripts from the PATH variable? (don't forget to open a fresh new terminal do get the new %PATH% value)
The problem is that your PATH variable doesn't include the paths of you python scripts. You need the full path of the Scripts directory. Not the relative path .\Scripts.

bash: 'command not found' for python, r and nano

On git bash, I receive a command not found message for python, r and nano.
I am on Windows 10. I do not know what I am doing wrong.
I type
r --version
python --version
nano --version
and they all return command not found.
I read something that had me try
alias python='winpty python.exe'
and it renamed python, but when I tried
touch .bashrc
it returned
touch: command not found
I followed the instructions in a Github course, PS239T. I have been fortunate, except for getting these three programs to work.
I tried
build/console.exe c:/Python36/python.exe
and it returned
build/console.exe: No such file or directory
I tried
PATH=$PATH:/c/Python36/
$ export PATH="$PATH:/c/Python36"
echo 'export PATH="$PATH:/c/Python36"' > .profile
and nothing.
I got Python 64-bit via Anaconda.
I tried setting up the Python 3.4 environment
conda create –n py34 python=3.4 anaconda
./python name_of_your_python_script.py
nothing.
which python
got me a huge directory path:
which: no python in (/c/Users/Edward/bin:/mingw64/bin:/usr/local/bin:usr
/bin:/bin:/mingw64/bin:/usr/bin:c/user/Edward/bin:/c/Program Files
(X86)/Intel/ 1CLS client:/c/Program Files/Intel/1CLS Client:/c/Windows
/System32:/C/Windows:/C/Windows/Sytem32/Wbem:/c/Windows/System32
WindowsPowerShell/V1.0:/c/Program Files/Intel/Intel(R) Management Engine
Components/Dal:/c/Program Files/Intel/Intel(R) Management Engine
Components/IPT:/c/Program Files (x86)/Intel/Intel(R) magament Engine
Components/IPT:/c/Program Files (X86)/Intel/Intel(R) Management Engine
Components/IPT:/c/WINDOWS/Syste,32/Wbem:/c/WINDOWS/System32
/WindowsPowerShell/v1.0:/c/Program Files (x86)/Rand McNally/RNDDock
/GtkSharp/2.12/bin/:/c/Program Files d/AppData/Local/Mircosoft
/WindowsApps:/c/Users/Edward/AppData/Local/Pandoc:/usr/bin/vendor_perl:
/usr/bincore_perl:/c/python36
I would have just put up the screenshot or copied and pasted it, but I do not know how.
I am sure I made an error somewhere.
I get the same type of results when I try to figure out what is going on with r and nano.
Update 1
Download and install 'Anaconda'
'https://store.continuum.io/cshop/anaconda/'.
Download the default Python 3 installer 'do not follow the link to version 2'.
Use all of the defaults for installation except make sure to check 'Make Anaconda the default Python.'
Install R by downloading and running
'this .exe file from CRAN'
'http://cran.r-project.org/bin/windows/base/release.htm'.
Also, please install the 'RStudio IDE'
'http://www.rstudio.com/ide/download/desktop'.
All you need is RStudio Desktop.
nano is a basic editor and the default that we use in this class. To install
it, download the Software Carpentry Windows installer
http://files.software-carpentry.org/SWCarpentryInstaller.exe'
and double click on the file to run it. 'This installer requires an active internet connection.'
Sublime Text is a more advanced editor. Download Sublime Text 3 'here'
'https://www.sublimetext.com/3'.
Update 2
I began trying janos advice and ran
/c/Python36/python.exe --version
and it returned
bash: '/c/python36/python.exe: No such file or directory.
I tried to run
PATH="/c/Python36:$PATH" python.exe --version
but it returned
bash: python.exe.: command not found
I tried to run
PATH="/c/Python36:$PATH" python --version
and it returned
bash: python: command not found
Update 3
janos told me I went too far without figuring out the problem, then told me to run
ls -l /c/Python36/python.exe
and it returned
ls: cannot access '/c/Python36/python.exe': no such file or directory.
janos told me to focus on the first error
bash: '/c/python36/python.exe: No such file or directory.
after entering
/c/Python36/python.exe --version
and so there I will focus.
janos asserted
Can you open a file explorer and navigate to C:\Python36, and see python.exe there? Probably not.
and is correct.
I ran
C/Users/Edward/Anaconda3/pkgs/python-3.6.3-h9e2ca53_1/python.exe
with no success.
I ran that in explorer and found that the publisher could not be verified.
Update 4
I went to
'python.org/downloads/release/python-363'
and downloaded 'Windows x86 embeddable zip file' and Unzipped it in
C/Users/Edward/Anaconda3/pkgs
it worked.
Thank you.
I bet I am having the same problems with 'r' and 'nano'.
I am going to run down the list again and perform all the check. I will do the same thing with 'r' and 'nano'.
Everything worked out for Python. I will do 'nano' and 'r' in due course.
I could not find
/c/python36/
so I used
/c/Users/Edward/Anaconda3/pkgs/python-3.6.3-embed-win32/
Update 5
janos is right again. I would need to create the python36 folder as it was not built automatically during the installation. janos' method worked on 'r' and 'subl' or sublime text 3. I gave up on 'nano'.
I found that some of my '.exe' files were in listing with spaces in the names. I moved to the user folder and eliminated any spaces.
I also downloaded version from the official website, and that too helped.
I could not figure out how to get 'nano' to work. I could not even find it on my pc. I used 'subl' instead.
Start from the basics. Try the simplest thing that can possibly work,
and make progress in baby steps,
from one sane state to the next.
The first step is to run a by entering its absolute path directly.
If the Python executable is at /c/Python36/python.exe, then run this:
/c/Python36/python.exe --version
This is very simple and it should just work.
If it doesn't, the command will give you an error message with clues.
A next step could be to simulate adding to PATH. Try this:
PATH="/c/Python36:$PATH" python.exe --version
This is one line. It sets a value to PATH in a way such that it's only active during the execution of the command. After the command completes, the value of PATH will be back to what it was before. This is a good way to test things. Also notice that I prepended to PATH the directory that contains python.exe, not the full path to python.exe.
That's an important point, this is how the PATH variable works.
It's a list of directories, and all executable files in those directories become easily executable by simply typing their name, without having to type their absolute paths.
Next, I would try this:
PATH="/c/Python36:$PATH" python --version
That is, see if you can drop the .exe from the name of the command.
I don't have Windows so I cannot test if this works.
And maybe it doesn't. (But I think it does.)
If everything worked so far, then the next step is to make the PATH setting permanent.
The way to do that is to put the command PATH="/c/Python36:$PATH" into a file that is always executed when you start a new Git Bash session.
If I remember correctly on Windows you can put it in ~/.profile
(a file named .profile in your home directory).
Where is ~? Here's one way to find it:
cd
explorer .
The above opens a file manager inside that directory.
You can use a plain-text editor like Notepad or Wordpad to edit it.
You can also use this shell command to append the line that updates PATH:
echo 'PATH="/c/Python36:$PATH"' >> ~/.profile
This line will get executed in all new Git Bash session.
Not in the current session,
because this file is only executed once.
If everything above worked, then in a new Git Bash session you should be able to run python --version.
If not everything worked, then you need to read the error message you get carefully, and not advance to the next step until the problem is resolved.
It's useless to advance to a next step when you are already not in a sane state.
You can follow the exact same logical process for all the other programs too.

Trying to access Python through Windows Command Prompt without adding Environment Variable

I am trying to access Python through a Windows command prompt, but am at an office and cannot add an Environment Variable. So, I cant follow the advice provided here. Thus, I added a User Environment Variable through User Accounts and use Variable:python and Value: C:\Python33. When I do a Windows Run check on %python% I reach the required Python33 folder. However, when I type python -Version in the command prompt I get the error 'python' is not recognized as an internal or external command, operable program or batch file. I am not sure how to proceed.
Run Python from the command prompt and include the full path to python.exe. For example to get the version:
C:\Python33\python.exe --version
When you run a script you specify the path to the script if you're not in the directory where the script is located. For example, if your script is in C:\scripts and is called my_script.py:
C:\Python33\python.exe C:\scripts\my_script.py
Instead of setting environment variables, you can use the whole path, like Neo wrote e.g.:
C:\Python33\python.exe yourPythonScript.py
Remove any environment variables you have added.
C:\Python33\python.exe pyscript.py should work.
I once Had a similar problem, but i couldnt find any solution, not even adding the path to the python folder was working.
Then I opened Python and clicked in File, then browser path, and I found that I had another folder that contained the real Python folder, not the default one. Maybe it could work for you too.

Environmental path to Python not working?

I have Installed Python 3.4 onto a new PC. Python works but I am trying to get pip to work on this. I have made a path for Python which is below.
C:\Python34\python.exe
When i run the below code
C:\Windows\System32>pip install python-docx
'python' is not recognized as an internal or external command,
operable program or batch file.
It seems that you haven't configured your PATH variable correctly. In order to do so:
Hold down the Win key and press Pause.
Click Advanced System Settings.
Click Environment Variables.
Append ;C:\Python34 to the PATH variable.
Restart Command Prompt.
(You may also just run set PYTHONPATH=%PYTHONPATH%;C:\Python34 in the cmd)
Further information is available in The Official Python Installation Guide for Windows.

Categories

Resources