I'm trying to run a simple Python script every time I build my app in Xcode. The Python script is called test.py and resides in my project folder as a sibling to my .xcodeproj file.
I think I followed the instructions in the Stack Overflow post
Is this possible to run a python script before Xcode doing compiling? but I am receiving the error Shell Script Invocation Error: Command /bin/sh failed with exit code 1
I installed Python 3.5.2, but when I type python -V into Terminal I get Python 2.7.10. However, when I type python3 -V into Terminal I get Python 3.6.0. Typing which python into Terminal returns /usr/bin/python, while typing which python3 into Terminal returns /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.
Following the instructions in Xcode: Running a script before every build that modifies source code directly I also moved the Run Script section in Build Phases to before Compile Sources.
This is what my Run Script section looks like. I have a strong feeling that the fix is annoyingly simple but have been unsuccessful trying to figure out what I am doing wrong / what search terms to use in Google or Stack Overflow.
And of course, let me know what other info I can provide to help debug.
EDIT: I have no preference for which version of Python I use other than that it allows me to run a Python script each time I build. I just installed Python 3.5.2 because I thought it might help.
EDIT 2: Tried deleting Derived Data (even though I am using Xcode 8.2.1) in addition to Clean (Cmd-Shift-K) and Cleaning Build Folder... (Cmd-Shift-Alt-K) and still no luck.
I managed to get this working by using /bin/sh as my shell and python test.py as my script.
In the "Shell" input, try this path: '/Library/Frameworks/Python.framework/Versions/3.5/bin/python3.5'
Related
I am veryy new in coding and wanted to get into it. So I downloaded VS code. But I tried to run a very simple python command and it does not let me. See the picture below.
Visual Studio code is not an IDE, it is a code editor, which means you cannot run nor debug code naturally, for that you would need to run it on the windows terminal, or install extra packages and dependencies. If youre new and just want to learn Python, i suggest starting with a python IDE like the standard one provided or something more advanced like Pycharm, and if you want to program on VsCode and in multiple languages, search some tutorials about how to compile and run code on the windows terminal.
Provide more details about how you installed python from Microsoft Store, from anaconda or via its official page https://www.python.org/downloads/. Try running
python --version
or
python3 --version
If so you can run a python file from terminal. Assuming my file is called test.py
python test.py
I am newbie with python and here is my problem. I installed python on my windows pc and as you can see on this picture, I checked it by the command python --version and it showed me the version, no problem.
But when I ran this very simple code:
my_text = "We made it!"
print(my_text)
It said to me that Python was not found! as you can see in the picture.
I searched on the internet, and add the path variable as they said in this guide:
Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings
but it still does not run.
Could you please give me some advise on how to solve this?
Try using python to run your .py file, like this
python test.py
If you are seeing instructions that say to use python3 to run Python scripts, it's probably because the author of those instructions uses a system environment where python is used for Python 2 and python3 is used for Python 3.
In your case on Windows, Python 3 was almost certainly installed using python as the command to run, so you should use python and not python3 to run your scripts.
I am trying to run Jmeter tests with the help of taurus in jenkins with performance plugin. In my yml file I have passed the scenarios to run jmx scripts and in jenkins I am using execute shell to run my tests
bzt test_suite.yml -report
I have also set the current directory as my workspace in jenkins. So, when I build the project in build console I get the following output
Running as SYSTEM
Building in workspace C:\Users\muhammad.taus\PycharmProjects\PerfAutomationFramework
[PerfAutomationFramework] $ sh -xe C:\Users\MUHAMM~1.TAU\AppData\Local\Temp\jenkins2737910596558040446.sh
+ bzt test_suite.yml -report
C:\Users\MUHAMM~1.TAU\AppData\Local\Temp\jenkins2737910596558040446.sh: line 2: bzt: command not found
Build step 'Execute shell' marked build as failure
Creating parser with percentiles:'0,50,90,100,' filterRegex:
Cannot detect file type because of error: Failed to copy C:\Users\muhammad.taus\PycharmProjects\PerfAutomationFramework\stats.xml to C:\Users\muhammad.taus\.jenkins\jobs\PerformanceAutomation\builds\36\temp\stats.xml
Finished: FAILURE
But previously the tests used to run fine on my host. I installed taurus using pip and in CMD When I type bzt it gets taurus, also when I type py it picks python and also I have setup JMETER_HOME and in cmd when I used jmeter it opens Jmeter. I am not sure what happened but I am not able to execute the tests anymore. The only thing I remember is changing python version from 32 bit to 64 bit, But I am sure that is not causing the problem. Please if anyone can help me in this regard it would be great.
You have some weird mix of Linux and Windows and your question doesn't contain sufficient level of details in order to troubleshoot the issue.
Use the full path to python executable in your shell script
Instead of bzt use /path/to/python -m bzt.cli your_config.yml
If you get No module named bzt install it using pip:
python -m pip install bzt
If python executable is not found, try python3 instead
More information:
Installing and Upgrading Taurus
Integrating Taurus with Jenkins
How to Run Taurus with the Jenkins Performance Plugin
I have a script that functions from within ipython but when I try and run the same script from the command line I receive import errors for a local module that I am trying to import:
from helper_functions.email_from_server import send_email
Error:
ImportError: No module named helper_functions.email_from_server
This script imports from within Ipython without any issues.
Comparatively, I have code that runs without any issues within ipython I can run another script using the command:
run script.py
From the command line I can run the same script:
python /dir/script.py
However this python /dir/script.py doesn't work with the script with local imports (from above) and I can't figure out if its a pythonpath issue or some local env issue? I have been reading through stack to find it but haven't been able to thus far. It feels like its just around the corner
One attempted solution:
PYTHONPATH=/dir/ python /dir/script.py
EDIT (to help clarify):
I am using an anaconda distribution on a linux machine.
Mucking about with PYTHONPATH is a recipe for sadness. You can do it, but you shouldn't. The correct thing to do is install your package in your correct environment. If you don't know how to create a package here's a super simple example. There may be some differences in your path when running via ipython vs command line.
You can find out what the differences are by using sys.executable and sys.path:
import sys
print(sys.executable)
print(sys.path)
Run that from IPython, and then run that from the python on your command line. You will undoubtedly get two different results. Since you're running Anaconda, you want to follow their guide for installing non-conda packages to install the one that you build.
Though of course that assumes that you've got the anaconda python on your path - you can check that out with which python since you're on Linux.
I resolved it via creating a wrapper shell script. Ugly in that i'm exporting the python path each time, but it works.
#!/bin/bash
export PYTHONPATH="${PYTHONPATH}:/my/dir"
source ~/.bash_profile
cd /my/dir && my/anaconda/location/bin/python /my/dir/to/script/cript.py
I am trying to install Sublime Text 2 on my linux machine and I cannot figure out how to run the python script to install it. I am fairly new to linux and never programmed in python before. I am trying to run the python script PackageSetup.py using ./PackageSetup.py but i get the error:
bash: ./PackageSetup.py: python: bad interpreter: No such file or directory
not sure what I have to do. I have python on my machine. I can tell cause running 'python' puts me in the console.
For all I know this kind of issue can occur if you have a misspelling or mistake in the shebang. I see two ways to solve this issue: you can try to invoke PackageSetup.py via python, like python PackageSetup.py or you can open PackageSetup.py and try to find an issue in the shebang, maybe it needs to be a full path to python interpreter like /usr/bin/python not just python.
BTW, why don't you try to install it via some kind of package manager - there is a repo for debian-based distros, and I'm pretty sure that there have to be repositories for other distributives.