xcode - Run the code in Terminal - python

I am coding a Python 2.7 script in Xcode. When click on build and run I get the confirmation it was successful, however nothing is shown. I would like to see the output the script in a terminal window.
Is there a way to get Xcode doing that for me, instead of having to open it on my own?

You can open Terminal from Application folder, then just enter
python gameover.py
If you don't have python in your path install it with
brew install python
If you are new to brew, install it from here http://brew.sh/
Here is a duplicate question: https://apple.stackexchange.com/questions/131375/how-run-a-py-python-script-in-xcode with same result
May I suggest you to try https://www.jetbrains.com/pycharm/ ?

Related

How to install Pyinstaller without cmd prompt?

I'm a beginner so there might be something wrong written, not a native speaker either...
I created a python script to edit some spreadsheets, and I'm wondering if there's a way to convert that to a .exe, so I don't have to open vscode every time. I did some search and find out that pyinstaller is a way to do it, but I couldn't figure out how to install it.
I'm using a corporate machine so I don't have access to the cmd prompt nor the terminal.
I can download the tar.bz2 file from anaconda.org, I don't know if that helps, but that's all I could do rn
You can download the Pip package as you have said and follow the steps of this link https://www.geeksforgeeks.org/download-and-install-pip-latest-version/ to install the downloaded package.
If you have an IDE called “PyCharm” installed on your machine, here’s what you can do:
The GUI Way
Go to the File Tab.
Click on Settings:
A dialog will popup. Click on Project: <Your Project Name>. Then click on Python Interpreter and then click on the + sign on the bottom of the dialog.
Another dialog will popup. In the search bar at the top, search for the package we want, in our case pyinstaller. Relevant results will appear. Click on the desired option.
Final Step. Just click Install Package at the bottom of the dialog and wait till it installs.
Hooray! You have installed the package.
The Integrated Terminal Way
Open Pycharm and at the bottom, click on the Terminal option this will open up the integrated terminal.
Type pip install pyinstaller and wait till it installs. You may have to use pip3 install pyinstaller. Wait till it installs.
Done!
Installing Another Terminal
If you don’t have PyCharm, you can choose this way. You can install some third-party terminal like Git Bash. You can download this terminal by clicking here.
After downloading, you can open Git Bash and try to run the commands that I mentioned in the above section. That’s it!
Note that if pip install pyinstaller or pip3 install pyinstaller doesn’t work, you may need to add python -m or python3 -m at the start of the commands.
Also note that the 2nd and 3rd options require pip and python to be in the system’s path.
Thank You!

Python PIP for absolute beginner (add Paths)

I am NOT a coder. I was trying to follow an online video when I stumbled on the PIP command for python. I have Python 3.9.
In the command prompt, if I type in PIP..I get
'pip' is not recognized as an internal or external command, operable
program or batch file.
Because I TRY to RTFM, another suggestion mentions using python as a command
C:\Users\TL>python get-pip.py
Python was not found; run without arguments to install from the
Microsoft Store, or disable this shortcut from Settings > Manage App
Execution Aliases.
Now I feel stuck. I am just trying write basic python code on a Windows 10 computer.
Any assistance is greatly appreciated.
UPDATE:
Upon futher review, this question is partially answered.
How do I add these paths to bee seen???
C:\Users\TL\AppData\Local\Programs\Python\Python39
C:\Users\TL\AppData\Local\Programs\Python\Python39\Scripts
By now, I have seen it mentioned a few time with no real explanation of where this is added.
ADENDUM:
I followed the instruction from the link below. The paths were added. PIP "Shows" as installed successfully. but the PIP command does not work. See picture
Python 3.4+ comes with pip: you don't need get-pip.py
Generally speaking, unless you've activated a virtualenv (which you haven't), you should prefer to always use python -m pip as you then have full control about which Python you're installing packages into. This is more commonly a problem when you have more than one Python installed
So, you want to use
python -m pip --version
I did not fully understand your problem, but I am assuming that you are using CMD. Check if you added Python to the windows path.
you can follow the steps in this link
https://datatofish.com/add-python-to-windows-path/
It's probably more user-friendly to use a terminal window than a command prompt like Jupyter as an alternative.
However, if you're looking to use Python using your Windows command prompt then you can type in Python3.9 , python or python3. Then, use the pip command to install any Python dependencies and libraries.

python -- manually install downloaded module without admin rights

I am trying to install the python package us without admin privileges.
I have tried pip install us in Anaconda prompt to no avail.
I have also tried the suggestion listed here: Install python modules on windows without admin rights--didn't work.
I have now downloaded the files from the site https://pypi.org/project/us/ to my desktop and need to know how to install the package from here.
I am using the Spyder IDE and Python 3.7. Is there a way to do this?
Thanks.
I do this on the daily and if I understand what you are saying you are doing it right. If pip install us in command prompt or shell (if you are using Windows OS) doesn't work try py -m pip install us. Make sure you are using command prompt and not using your IDEz
As you can see it worked first try for me.
Since you have downloaded the files, Extract them in a folder and normally a setup.py file must be include, open command prompt in that folder and run :
python setup.py install

VSCode: There is no Pip installer available in the selected environment

I'm trying to run the autopep8 linter on a Python file in VSCode.
I've followed the instructions here: https://code.visualstudio.com/docs/python/environments and selected my interpreter (⇧⌘P): /usr/local/bin/python
I then try to format my code, and VSCode says autopep8 isn't installed, and can be installed via Pip. However, when I try to install via Pip, it says There is no Pip installer available in the selected environment.
I then tried launching a terminal in the current environment by selecting Python: Create Terminal from the Command Palette.
The terminal opens fine, pip is present, and I'm even able to pip install autopep8 in the terminal that opened in VSCode, but when I try running the Format Document command I get the same errors that autopep8 and pip aren't available in the environment.
On Ubuntu16.04, I worked with Python3 in vscode and
apt-get install python3-pip
solves my problem.
That's because I discover that: Under my terminal, I type the pip -V. It displays it's for Python2, not for Python3.
Man you can only change the interpreter.
Go in (ctrl + shift + p), then type Python: Select Interpreter, this way you choose the version that your extension needs.
This worked for me.
I have multiple python versions:
2.7
3.6
3.7
Tell the vscode/ visual studio code, which version to use:
press the following (Show All Commands): Ctrl + Shift + P
paste the following: Python: Select Interpreter
Select one of the version that it shows, I have selected python 3.7.3 64-bit
Update python path in settings:
press Ctrl + , to open Settings
search for python.pythonPath
change python to /usr/bin/python3.7
Note: this may not be needed, however, make sure /usr/bin/python3.7 really exists for you, you may have at a different path like /usr/local/bin/python3.7, etc.
I had pip but it was 2.7, but since I am choosing python 3, it's pip needs to be installed
Run the following command in Terminal: apt-get install python3-pip
Restart vscode
With the above steps, all issues got resolved. Hope that helps.
try Ctrl+Shift+P
then type
Python: Select Interpreter
and select the python version.
Installing python3-pip fixed the issue for me.
apt-get install python3-pip
1.Select the File > Preferences > Settings command (⌘,) to open your User Settings.
2.Search and Create or modify an entry for python.pythonPath with the full path to the Python executable according to your requirements.For Example i changed it to python2.6 path to this path /usr/local/bin/python3.
I had the same problem today, none of the solutions helped me. Eventually, I figured it out myself.
I'm posting this answer for people who are having this problem. Just go to your ./venv folder and you will find a .cfg file.
Just make sure include-system-site-packages is set to true
home = /usr/bin
include-system-site-packages = true
version = 3.8.5
If it still doesn't work, just run sudo install python3-pip once in the terminal. Of course you could always change the version here as well.
(on mac)if you are using python3 but vscode told you pip was not installed , you could change python version on vscode bottom.
And I guess you are using another terminal but not bash , vscode's default terminal is bash. Bash don't know you have install pip#2.
For WSL users:
If you have your work files in linux subsystem path, you still need pip for windows in order to VSCode to use it.
On Ubuntu:
Make sure, that you have Python and pip installed.
Go to Settings, type python.py in search input. This should find Python Path settings.
Remove this path (if it is currently setted), save. Exit Code and set this to current value.
For me is /usr/bin/python3
Had this issue when trying use autopep8. For me - it had nothing to do with pip (I know it is installed) but the path the VScode python extension was using.
If you open up the extension and go to it's setting and scroll down, there is a path you can designate for autopep8: Python › Formatting: Autopep8 Path
I used the path recommended by these docs:
https://code.visualstudio.com/docs/python/editing#_formatting
Which was: python.formatting.autopep8Args
I stopped getting the error.
For Windows system check the environment variable>System variables
check the Path variable for the python path.(if not found set the path variable for python)
Copy the path and paste under vscode>file>preferences>settings>python.pythonPath
It worked for me.
I ran into this problem while learning django and the terminal would not let me pip install anything.
Create a virtual environment in shell and then use the path of the environment as your interpreter. This worked for me.
Note: You might want to create to create the environment in a different shell altogether and then upload the folder of the environment into vscode.
Then you open up the settings file in the environment folder.
This image will hopefully give you a good idea. Click Here
I was having a similar problem with pylint in a docker container. I realized that the reason the VS-Code-prompted pylint install didn't work for me was because I was using the global python installation (global inside my docker container, anyway), which can require elevated permissions to install things and VS code wasn't running as root in the container. According to the vs code python extension docs:
Note: If you're using a global environment and VS Code is not running elevated, linter installation may fail. In that case, either run VS Code elevated, or manually run the Python package manager to install the linter at an elevated command prompt for the same environment: for example sudo pip3 install pylint (macOS/Linux) or pip install pylint (Windows, at an elevated prompt)
Go in (ctrl + shift + p), then type Python: Select Interpreter,
then type Python: Select Interpreter and then click on "Enter interpreter path"
Then click on "Find.. Browse your file. "
Then type Python in c drive search bar and click on latest version of python in case if you have multiple version of python. Enter and modify wait for sometimes to complete then close.
After that restart your vs code.
It worked for me it will work for you also.
Note: This is a solution for Windows.
First make Sure your Python is installed properly. Run the following command:
py --version
If the Previous command is running fine it will give you your python version. In that case go ahead and check if pip is present or not. Run the below command to check:
py -m pip
If pip is present in your system it show give you a list of option and info. If that's the case then go Ahead and run pip. All you need to do is precede the command you would normally write with py -m. For example:
pip install flask
py -m pip install flask
This should solve your problem.

get-pip.py raises ValueError when run in IDLE

enter image description hereI need to install PIP for Python 2.7.3.
I have run the get-pip.py file in Python IDLE shell. However, it raises the following exception:
ValueError: Unable to configure handler 'console': closed
Here is the screenshot:
How can fix this error?
Here is the error faced when trying to execute python get-pip.py in the command prompt:
inspite of correct path no execution result
You need to run Python as an elevated process in order to have write access to the program files directory where pip will get installed. The simplest and best way to do that is to launch an elevated command prompt cmd.exe.
In Windows 7 and later, you can best do that by opening the start menu using the Windows key, and then typing cmd. This should give you the command prompt as the first result. Right click on it, and choose “Run as administrator”. After accepting the UAC dialogue, this will then start an elevated command prompt with proper write access.
The run the script, then use the following command as explained in the pip installation manual:
python get-pip.py
Of course you need to adjust the path to the get-pip.py file. For example if the file is in your downloads folder, you can write the following:
python C:\Users\<username>\Downloads\get-pip.py
This should the properly install pip for the current Python version.
Note that in order to use pip later, you also need to run it always from an elevated command prompt, as every PyPI module is also installed into the Python directory in your program files (unless you’re using virtual environments of course). So you then need to run e.g. pip install beautifulsoup4. If pip.exe is not in your path, which likely be the case, you can also run pip using the Python executable like this: python -m pip install beautifulsoup4.

Categories

Resources