So I'm a teacher at a school, and I don't have the ability to install very many things. We currently use Windows 7. I can't change any environment variables.
I have installed the following software:
Ruby 2.2.4 with Command Line Prompt
Python, including IDLE
Is there any way to have a portable version? I can put them onto USB sticks.
I only want to run the most basic unix commands:
Like getting the word count of a file:
wc file.txt
Or displaying the contents of a file:
file file.txt
Literally, very basic commands like that. It's part of an exercise for my students.
Find a portable Cygwin(https://github.com/GathSystems/CygwinPortable for example). I've used it exactly like you - from usb stick.
Busybox on windows should work just fine for what you want to do.
You don't need to install anything. Just downloading the stand-alone executable should be enough.
Executing busybox.exe bash would bring you a shell which knows wc, file and cat among many other commands.
Related
I am following Ben Eaters tutorial on the 6502 computer and I'm completely lost on the python programming stuff. I have a little bit of programming knowledge, but not enough to understand which programs he is swithcing between. Here is the link to the video I'm referring to (around the 9:40 mark): https://www.youtube.com/watch?v=yl8vPW5hydQ&list=PLowKtXNTBypFbtuVMUVXNR0z1mu7dp7eH&index=2
I've created my "makerom.py" program in Visual Studio Code and it appears I was able to run it via the CMD prompt. But when I try to hex dump from there it doesn't work.
Here is my python program:
rom = bytearray([0xea] * 32768)
with open("rom.bin", "wb") as out_file:
out_file.write(rom);
I've created my "makerom.py" program in Visual Studio Code and it appears I was able to run it via the CMD prompt. But when I try to hex dump from there it doesn't work.
Too many questions to ask to clarify what you are asking. I would use Python for Windows if you're on Windows and then call > python.exe YourScriptName.py from within PowerShell. If you're on Linux just use your bash terminal and call $ python YourScriptName.py.
Your program above works. To check the file that it creates, navigate to the same directory that you ran the script from, and you should find a rom.bin file. If you don't see that exact file, your program either didn't work or likely didn't run. But if it's there than your script at least created the file. So then, if you want to see what's inside, if you're in Linux you can run $ xxd rom.bin or hexdump. If you're in Windows you can use PowerShell's > Format-Hex .\rom.bin to confirm the data was written to the file.
I will preface this with, I know questions like this have been asked, but I feel as I can't find my answer.
My question is this: I downloaded Python about 2 months ago to begin learning it. I just recently starting trying to use the terminal more and would like to move forward using it a lot for commits and package installs.
Unfortunately I am having a very hard time getting Python to run properly through either Git Bash or Windows Powershell. I think i may have moved files around too much before even starting with using the terminal and now I'm not sure what's correct.
Should I uninstall and re-install?
I am on Windows 10, any advice onhow to organize my files properly so everything can run correctly. I would also like to be able to open my text editor from the terminal, PyCharm or Atom.
Thanks in advance!!
Try first to simplified your PATH (as I did here) in a CMD session.
set PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem
set GIT_HOME=C:\Path\to\Git
set PATH=%GIT_HOME%;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%PATH%
SET PATH=C:\Users\Aerovistae\AppData\Local\Programs\Python\Python36-32;%PATH%
Once you have the right path, you can replicate it in your user environment variables.
(replace C:\Users\Aerovistae\AppData\Local\Programs\Python\Python36-32 by your own Python2 installation path)
Then type bash and check python does work.
I was going through Google's Python instructions and it quotes:
The commands above are the simplest way to run python programs. If the
"execute bit" is set on a .py file, it can be run by name without
having to type "python" first. Set the execute bit with the "chmod"
command like this:
Where it proceeds to give me this code to run on my terminal:
~/google-python-exercises$ chmod +x hello.py
~/google-python-exercises$ ./hello.py ## now can run it as ./hello.py
Hello World
However when I type in ./hello.py, I get:
So is this something to do with me using Python 3 when this could be a command for Python 2?
EDIT
I just realised that this can only be run on a Linux/Mac. How does one go about doing this on a Windows?
You need to associate the file extension with Python properly. This should happen by default if you install system wide (which requires administrator privileges), but if you're using a third party distribution, it's not guaranteed, and it may require a reboot even so.
For more details running Python on Windows, see the Python on Windows docs. It looks like if you omitted the launcher from your Python install, it won't have registered the file extensions; it may be worth reinstalling properly to fix that.
Otherwise, if you can't get file extension associations working, just run:
python hello.py
or starting with 3.3 and later, you can use:
py hello.py
which lets you provide an argument to py.exe to change which installed version of Python to use (if desired).
You wouldn't use ./hello.py on Windows at all, because that's the wrong directory separator (Windows sometimes allows forward slashes, but in DOS prompts, that looks like trying to launch a program named . with the switch /hello.py). You'd use plain hello.py (Windows always searches the current working directory) or .\hello.py if you want to be explicit.
Do you have a shebang as the first line in hello.py?
something like:
#!/usr/bin/env python3
I built a python/bash application for OSX that I want to distribute to non techsavvy users. My problem is how to get the user to initially run my python script. The script sets up a cron job so the user never has to do anything again but the user MUST run it the first time. The issue is that python and bash scripts default to non-executable when unzipped. As of now I have instructions in the readme.txt for the user to open the terminal and copy and paste the command which chmods the script and runs it for them. However is there anyway I can accomplish this without having the user open the Terminal? Ideally the user could just double click the python script and have it run. Thanks.
Sometimes being user-friendly warrants using platform-specific features. In this case, the Mac OS X "Installer" system: http://en.wikipedia.org/wiki/Installer_(OS_X)
Rather than a .zip file, you can create a .pkg file which users can download and install just as they would any other program native to OS X. This should give them a familiar experience, and you can make the .pkg file do what you need behind the scenes.
I am running Windows 7 and just installed Python 2.7.4 and all I get are SyntaxError:'s. For example when I type:
>>>ls
I get
Traceback (most recent call last):
file "<stdin>", line 1, in <module>
NameError: name 'ls' is not defined.
I am new to Python and have no idea what the problem is.
Math calculations work as well as code seems to work. It's just commands like cd, ls, sudo apt-get update (and upgrade). Any guidance would be appreciated.
I think it's unfortunate that you're being downvoted so heavily here. If you're new to programming, this can be an honest mistake to make since a lot of tutorials assume that you're already familiar with the command line.
The main problem you have (as others have pointed out) is distinguishing between the operating system shell (which is also known as the console, terminal, command line, or command prompt) and the Python shell.
The operating system shell/command prompt is one of the fundamental ways you can interact with your computer. When you open the command prompt, you run arbitrary programs by typing in their name, run commands such as ls, sudo, cd, and apt-get.
If you type in python, for example, it'll cause the command prompt to start the Python shell. From there, you can run all of the Python commands, as usual. However, this is an entirely separate program with an entirely separate set of rules. The things you can do in the command prompt will not work in Python, and vice-versa.
Now, another point of confusion is distinguishing between the Windows command prompt and the Linux command prompt. You can install and run Python in both, but certain commands (in particular, sudo and apt-get) are available only on Linux operating systems. Unfortunately, the rules for using the Windows command prompt and the Linux command prompt differ somewhat, meaning that some instructions you find will be applicable only in one kind of operating system.
So no wonder you're confused! You're trying to learn about Python, but a good number of tutorials/articles will mention this second, entirely different system with hardly a word of introduction, and expect you to already know how to use it.
If you're curious about learning more about using the command line, here's a good crash course you can read. It'll teach you what you need to know for all 3 major operating systems (Windows, Linux, and Mac) and will hopefully make what you read online more clear.
I see from your profile you are learning about Raspberry Pi. A Raspberry Pi can use Debian (or Ubuntu, which is based on Debian) as the Linux distribution. The commands you are trying in Python are shell commands to run on that operating system.
Python is another command you can run on Raspberry Pi, but that doesn't mean that installing Python on Windows gives you those other commands on Windows too. You have two entirely different things confused here.
it's just commands like cd, ls, sudo apt-get update (and upgrade). Any
guidance would be appreciated
Python doesn't support those commands. Those are operating system level commands, not python level commands.
The Root of my problem was that I was not asking the right question. I was trying to run scripts in the interactive-mode and entering 'ls' and 'dir' to see where I was in the directory. With everyone's guidance I finally found the part in the Docs about Executable Python Scripts that said Windows automatically associates the 'py' extension with python.exe.
here. Then it all came together in my head. I had associated the 'py' extension with my editor instead of python and that I should have been at the Windows command prompt.
Thanks for everyone's help and quick responses.
The answers above are correct, but they don't help you with your issue!
One solution that will work in Python is:
%ls