We are using jenkins to run a python script through command prompt. The command is like C:\Program Files\...\someapp.bat test.py. The someapp.bat is a customized python and it has a library called arcpy. The test.py file includes a statement import arcpy.
This command works fine on command prompt on the machine. However, when running through Jenkins, it complains arcpy does not exist. Then I used ssh to access the machine and ran the same command. It has the same error. Then I compared the path in the two command prompts (on machine and ssh), the environments has only one difference which is the Windows. One under user folder and the other under system. But it does not seem to be a dependency of the python bat.
So, in general, what's difference between a remote command line window and a local command line window if logged in as the same user? Any clue is helpful!
Related
I'm trying to run a remote ssh debugging session in Visual Studio Code. The only problem is the destination system, which is NixOS and i'd like to run a command nix-shell -p python38Full before launching the project.
I know about tasks, I've tried configuring them, but it runs in different terminal, which isn't helpful, because the command above creates shell for executing python environment.
Can I add a line to Python's launch command or execute a command right before launching?
I'm migrating from Spyder to VSCode and would like to use it in a similar way.
One of the major problems I'm facing is to set de cwd to the folder of the file I'm working. There is a lot of question just like mine in the Google, but none of them solved my problem.
Here are my configs:
"code-runner.cwd": "${fileDirname}",
"code-runner.fileDirectoryAsCwd": true,
"terminal.integrated.cwd": "${fileDirname}",
"python.testing.cwd": "${fileDirname}",
"python.terminal.launchArgs": [
"-m",
"IPython"
],
"terminal.integrated.defaultProfile.windows": "Command Prompt",
"python.terminal.executeInFileDir": false
What I want to do is to execute my file in IPython with the cwd setted to my file directory, to load some CSVs that are in the file folder, also be able to run some independent lines or enter some code directly in Ipython with all the variables loaded.
I don't want to just RUN the file or DEBUG, because I want to prototype some lines of code right in the IPython console with all the variables loaded.
With my configs, what I usually do is to select all the lines of the script and CTRL + ENTER. This will open a terminal with Ipython but setted to my project folder, not my file folder.
If I open a REPL, I get the same problem: Ipython opened but not set to file folder. Worse I can't use the CTRL + Enter to send some independent lines to Ipython (in this situation CTRL + Enter will cause to open a new terminal)
If I open a terminal by the Terminal menu, the console is setted to my file folder, but without python.
The closest that I got is to open the terminal from Terminal menu, and in the terminal navigate to my python and execute IPython, but then I can't run some independent lines from my code using a shortcut (most precisely like the F9 in Spyder)
My Python is not in Windows path. I'm working with files from a disk E: and my python is on a disk C:.
No Work Reason:
"terminal.integrated.cwd": "${fileDirname}", is the configuration of the default terminal. You can find out the terminal name was powershell or something others. But when you take the command of Run Selection/Line in Python Terminal, the name of the terminal was the explicit name: Python.
Impossible Reason:
Unfortunately, the Python extension seems has not provided the configuration to modify the cwd when you take the command of Run Selection/Line in Python Terminal while you can modify the cwd when you take the command of Run Python File in Terminal. As the IPython has no configuration to modify the cwd too, so it seems has not a suitable method to achieve your aim.
Workaround:
Method1: After you into the REPL mode, modify the cwd like this:
import os
os.chdir('/tmp')
Method2:
Change the configuration: "python.terminal.executeInFileDir": true
Execute the command of Run Python File in Terminal first, in order to change the terminal path.
Execute the command of Run Selection/Line in Python Terminal.
Method3:
Execute the command of Run Selection/Line in Python Terminal.
Exit out and change the path of the terminal.
Run IPython again.
Would someone please suggest a way to execute Windows PowerShell commands (i.e., commands more similar to Unix commands than Command-Prompt commands) in a Jupyter notebook? Please note that I am a layperson.
So far, I have added "C:\ProgramData\Anaconda3\Scripts" to my path system variable, which allows me to run "jupyter-notebook" from either Command Prompt or Windows PowerShell. I guess a shell looks in all folders in my path system variable for an application to run named "juypter-notebook". I guessed that running Jupyter Notebook from Windows PowerShell would allow my Jupyter-Notebook Chrome application to understand PowerShell commands, but this doesn't seem to be the case.
You can execute a PowerShell command from a Jupyter Notebook cell on a Windows machine with:
!Powershell.exe -Command "<PowerShell command>"
For example, if you wanted to print the first 10 lines of the file filename.txt, you could write:
!Powershell.exe -Command "type filename.txt -Head 10"
Source
so far I have been ok with debugging and running in a python debug terminal. Now that I'm being forced into functions, i have to input the arguments when launching the script, for example:
./python.py BIRTHDAY AHMED
and have it spit out something along the lines of this:
have a happy BIRTHDAY enjoy the day AHMED
problem comes down to me not knowing how to setup a terminal for such use. i have a bash terminal, however it wont recognize my python interpreter (#!/usr/bin/python3).
I added "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" to my user settings to gain the bash terminal as well as installed Git.
Any ideas on how i can get a work in terminal that i can input arguments and recieve an output would be most appreciated. (running on windows 10)
You are providing the path of Git Bash, which only provides enough bash-like functionality to use git. That is why running .sh (Bash Scripts) or .py files doesn't work by default.
If you add python to your PATH environment variable, that will make it so running python.exe filename.py [ARGS] will work on the Integrated Terminal.
Another solution is to install WSL if you are on Windows 10, which does provide full* bash functionality under a modified Ubuntu shell. Then just provide VSCode the path to the WSL bash.exe. (How to here)
I have a python file in which I'm using the subprocess module to execute some command line scripts.
I'm using Git bash to run this python file. In the file, I execute the script:
KG_URL=http://127.0.0.1:8900
This script sets the variable successfully when I run it manually on the git bash command line.
But when I execute this using the python file, it gives me the following error:
'KG_URL' is not recognized as an internal or external command,operable program or batch file.
I tried digging deeper into this and I found out that executing the python file on git bash is the equivalent of running those scripts on the Windows cmd. When I tried running the set command without parameters (to get the current environment variables) on the Windows cmd, I found out that the variable KG_URL does not exist. But when I ran the same command on git bash, I can see that KG_URL exists.
Any idea why this discrepancy exists? And how can I solve this issue?
The reason why I'm executing these scripts in a Python file is because I need to convert it into an exe later. Assuming that all environments where I run this exe will have git bash installed, is there any way of ensuring that these scripts run only through git bash, and not the Windows cmd?