bash on Ubuntu on windows Linux, folder recognition, and running Python scripts - python

I'm new to Linux. I recently downloaded Bash on Ubuntu on Windows 10 (after the Anniversary edition update to Windows 10). Since this update is relatively new, there is not much online regarding troubleshooting. There are two things I need help on:
(1) When I go to the home folder, which seems to be "C:\Users\user\AppData\Local\lxss\home\user" and I add a new folder through Windows, this folder does not show up in Linux with the "ls" command. But when I add a directory using "mkdir" in Linux, the "ls" command shows this folder. Why is it behaving like this? Am I limited to creating folders through "mkdir" when working in this folder?
(2) I have a Python script sitting in that same folder that I'm trying to run and again it is not being found by Linux or the Python interpreter started in Bash on Ubuntu on Windows. I have Python 3 installed (Anaconda) and I'm able to type commands directly in the Python interpreter and it's working. However, I would like to run scripts in files.
Please let me know if more information is needed. Thanks.

The reason why ls is not showing anything is that it shows the Linux directory structure. Try setting it to the Windows directory, in this example the c drive:
cd /mnt/c
Does ls show a folder structure now?

Looks like you are having permissions issues.
To see everything on your home folder try
ls -al
to change permissions check out the chmod command

How about using Python for Windows and NotePad++ to edit and run your Python scripts?
https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe
You can setup NotePad++ as described here.
How to Execute a Python File in Notepad ++?
(I ended up using Cloud9 https://c9.io/ for Python. It is independent of your local environment or OS)

Related

How to run Python3 function script in terminal Visual Studio Code

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)

Pycharm (Ubuntu) program not opening

I am running Ubuntu 14.04/GNOME 3.8.4 on 15 MBP Duel Boot.
I am new to Linux and Python(Pycharm ide)
I have downloaded the Pycharm "files" from the software center
but cannot run the program.The icon comes up in the side bar but when i click it nothing happens. I have tried "./" and only the code appers in "gedit" Please help Oracle java is already installed
Alternatively, after extracting your pycharm.tar.gz,
add the following in .bashrc file (which is in home folder itself, to view hidden files use ctrl+h)
alias pycharm='~/tools/pycharm-4.0.6/bin/./pycharm.sh'
OR In your case it might be,
alias pycharm='~/Downloads/pycharm-4.0.6/bin/./pycharm.sh'
And, then restart the terminal and type,
pycharm foldername
It should open the pycharm with given folder.
hi Pedro in ubuntu you need to install the files using the command prompt even if you downloaded the files you need to install them using command, unlike windows in linux when some software is downloaded you need to install them manually by using commands like sudo apt-get python install..
for further help you can consult http://linuxg.net/how-to-install-pycharm-3-4-on-ubuntu-14-04-linux-mint-17-pinguy-os-14-04-and-other-ubuntu-14-04-derivatives/

how do we setup s3cmd on windows7

I have successfully installed s3cmd(http://s3tools.org/s3cmd) on a windows 7 machine. I first installed python 2.7
added python to my path
then ran python setup.py install
I also added the python\scripts folder to my path but I can't run s3cmd from the dos prompt by simply running s3cmd but I can run the command if I use the full path like this
> python c:\Python27\Scripts\s3cmd
My issue is that I use ruby rake to automate some tasks and it needs to run on both windows & mac, is there a way I could simply run s3cmd like I would on linux or a mac?
Thanks!!
Just in case: we built a free open-source analog s3cmdwin - a very (very!) simple command line tool to upload a file to s3 or list existing files in a bucket, based on Amazon's nuget-published SDK.
Disclaimer: I'm one of the contributors.
Type this in a s3cmd.bat (or s3cmd.cmd) in a place somewhere in your path:
python C:\Python27\Scripts\s3cmd %*
And you should be able to cast commands like s3cmd sync --etc...!

Running python from the mac terminal

I have installed the new python release and would like to run .py files from the terminal.
How is this done from the terminal? I dont want to include the path in each command to run a .py file.
If you want to override the python command, you can set your PATH variable correctly, e.g. in your ~/.bash_profile:
export PATH=/path/to/python/:$PATH
That said, for managing different versions of components that are also provided by Mac OS X, I suggest to use a package manager such as Homebrew.
if you add a shebang at the start of the python file then you can run a python file by just its name from terminal
add #!/usr/bin/python
for mac(others add your respective path for python)
at the top of your python program and from your terminal you can run it just by filename(if it has executable permissions).
Have a look at the Python package under Applications. There is a shell script there called Update Shell Profile.command
Run this and it should set your path up properly.
Unless you mark you script as executable with chmod +x, you'll need to run python over it first. e.g. `python myscript.py'
I installed all of my python through macports, which has pros and cons. One of the benefits is that you don't have to worry about stuff like this, it just works. You can install python 2.6 and python 2.7 (and others), and then use the python_select utility to set up which python is run when you call "python blah.py"
Since you have installed a working python, the easiest way to run python files from the terminal is to cd your terminal to the directory where the file is located and then just type python my_code.py in the terminal.

How to set python enviroment variable on windows

I've downloaded python installer from http://www.python.org/ftp/python/3.1.2/ , this python-3.1.2.msi file, I need to execute some python files? How do I do that? For example in php I'd do php filename.php from console, I do however have python command line but I don't know how to execute those files.
So if I could set ENV variable to directly execute my file(s) if that is possible that would be great.
There is an option in the installer called "Register Extensions" to associate Python files with the interpreter, so double-clicking them or entering filename.py in the console should work.
Apart from that you might want to add C:\Python31 to your PATH variable (right-click on My Computer, choose Settings, choose the Advanced Tab - there you can access the system variables. Better do this as an admin.
If you type python in the Windows command line, what happens? Is the Python interpreter in your PATH yet?
If not, add the Python installation directory there (here's a good guide). Then just do python script.py just like with PHP.
you can just execute
python yourfile.py
Or if the python command don't work you have to give the absolute path to you python installation or add it to windows path

Categories

Resources