My Visual Studio Code installation (v.1.59.1) is behaving strangely. Any command I type in the Terminal results in the error "The term 'myCommandHere' is not recognized as the name of a cmdlet, function, script file, or operable program."
This includes but is not limited to variable assignments, as per the above, although non-variable computations work.
I'm new to Python so I often try simple toy bits of code in the terminal to see if they'll work as expected. But since this problem appeared, I cannot use the Terminal for this, and need to run all code as .py scripts (which works fine).
I am on Windows 10, and VS is running with admin rights.
Related
I will try to be brief!
For whatever reason, I couldn't make the entirety of my program in python, so I had to outsource one specific task to php (a language I do not know very well). As the python program runs, it is supposed to trigger the php program to run, and then do a few things afterwards which is not a problem.
It seems to me that, to be able to run something through python, you need it to be able to run through cmd first, and then you can make python use cmd to run the program. I had a few issues there, because the programs are on different drives, and the php program references other files and locations in the same directory and in sub-directories to where it is, this means I couldn't execute in one line of cmd, but first had to change directory, to then execute the php program from the folder it's in. Because my command wasn't just one line, I made a batch file containing all the steps.
My current working method is to open up cmd, change directory in cmd to where the php file is, and then run the php file. I had to add php to the "Environment Variable Path" to be able to do this. Here is the batch file that currently works when run by me:
cd /d C:
cd C:\Users\UserMain\Desktop\php\colorextract
php (2).php
When I double click this bat file, from my E drive, it successfully executes the php program. But when I tell python to execute the batch file, that is where things go wrong.
Here is my python code, apologies for the name of the bat file:
import os
os.system('cmd /k "bitch.bat"')
The resultant cmd window then goes thru the steps of the batch file: 1) it changes to the right directory, 2) it is unable to execute the php file because:
'php' is not recognised as an internal or external command, operable program or batch file.
Now, this is the standard error you get if you were to try running a php program without having added php to the "Environment Variable Path", I know this because I went through that same thing. But if I manually open a cmd window, not administrative or anything, I can 1) successfully perform the steps outlined in batch file, and program runs, and 2) I can even run the bat file, and that also runs the program.
The cmd window opened by python does not seem to be able to reference the "Environment Variable Path", or it is for another reason somehow handicapped against being able to do all the things that a normal cmd widow can. How can this be fixed?
Thanks in advance to anyone who reads this!
Edit: I found that python had not detected the changes I made to the environment variables the day before, hence why python's cmd was giving the exact error that not having php in the environment variable gives. After I restarted my computer, my code worked. Thank you to #Gerhard and #Aaron Junker for making me think much harder about this issue.
so I found a command that can be run after importing os.
print(os.environ)
I ran this, and it told me that Python could not see that php had been added to the environment variables, well, more likely that python did not have the most up to date information regarding what was in the path variable(s).
Restarting my computer made the changes kick in, and now my original code works. Whilst I do feel very stupid, I'm just happy that this is resolved.
This seems to me like both instances use different environment variables.
Open
System Properties -> Advanced -> environment variables and look that PHP is in the PATH variable in user variables and in System variables.
I am trying to run the flopy3_modflow_boundaries example from the FloPy Jupyter Notebook. The notebooks have worked perfectly well for earlier examples (including building, displaying images, running a MODFLOW-NWT model, and viewing the results...so I think have things substantially set up correctly), but for some reason when it gets to the following section of code:
!head -n 10 'data/test.riv'
I get the following error:
'head' is not recognized as an internal or external command,
operable program or batch file.
I'm not sure what the "!head" code with the exclamation mark is supposed to do, or how I can fix the error. If it matters, I'm running Python 3.9 on Windows 7. "Head" is a groundwater term, so I assume it is imported from FloPy in the first step of the notebook?
Thanks!
head is a Unix/Linux shell command to show the first n lines in a file. So running head -n 10 'data/test.riv' would output the first 10 lines in file data/test.riv. Note that when you precede a command with ! in a Jupyter cell, it runs the command as it would in a terminal, and not as Python code.
You can do any of the following:
Run the code on a Unix/Linux machine which has the head command.
Skip the command as it probably will not affect the rest of your code as it is meant to just show you the first 10 lines in the file, which you could just do by opening the file in a text editor.
Replace the command with an alternative command for head in Windows to perform the same function, although AFAIK, there isn't a direct equivalent.
I keep getting this error while working in a script:
'python' is not recognized as an internal or external command,
operable program or batch file.
Isn't this an error you'd see in terminal? I'm in Atom text editor. On top of that, it was working a few minutes ago (i.e. giving me errors about my actual code) and I've been working on it with no problem all day long.
Reinstall Python, and make sure you check the 'Add to Path' option.
You could also try adding Python to the path variable (Tutorial).
I am new to python and wanted to make a simple script that acted like the ls command in a mac/linux terminal but for cmd in windows. The code itself works and if I run the script using python ls_script.py in my cmd it works fine. However, I want to make it so that I can run it in any active directory by just typing in ls in my cmd. I made an environment variable in cmd called ls that has a value of python ....\ls_script.py, which assumed would work since if i were to type that exact thing in manually, it works. However, when I just type in ls, it gives the following error:
"'ls' is not recognized as an internal or external command, operable program, or batch file."
I don't think your problem has anything to do with python, considering that the python script does what you want. The problem is getting the environment variable to work, right?
I believe this question has the answer you're looking for:
How to create ls in windows command prompt?
In short, it looks to me like the way to achieve what you wanted was to not use environment variables, but to create a batch file instead.
EDIT: I got it working, I went into the pycassa directory and typed python pycassaShell but the 2nd part of my question (at the bottom there) is still valid: how do I run a script in pycassaShell?
I recently installed Cassandra and pycassa and followed the instruction from here.
They work fine, except I cant get pycassaShell to load. When I type pycassaShell at the command prompt, I get
'pycassaShell' is not recognized as an internal or external command,
operable program or batch file.
Do I need to set up a path for it?
Also, does anyone know if you can run ddl scripts using pycassaShell? It is for this reason that I want to try it out. At the moment, I'm doing all my ddl in the cassandra CLI, I'd like to be able to put it in a script to automate it.
You probably don't want to be running scripts with pycassaShell. It's designed more as an interactive environment to quickly try things out. For serious scripts, I recommend just writing a normal python script that imports pycassa and sets up the connection pool and column families itself; it should only be an extra 5 or so lines.
However, there is an (undocumented, I just noticed) optional -f or --file flag that you can use. It will essentially run execfile() on that script after startup completes, so you can use the SYSTEM_MANAGER and CF variables that are already set up in your script. This is intended primarily to be used as a prep script for your environment, similar to how you might use a .bashrc file (I don't know of a Windows equivalent).
Regarding DDL statements, I suggest you look at the SystemManager class.