admin管理员组文章数量:1333661
I am new to Python and still trying to get past something more practical than copy&paste (and I do search for answers and try everything suggested before posting a question)... I have tried Laincher, VSC, Jupyter, and all either have problems each is different) or the graph plot when displayed loses the tool bar. Copy script ( RGB_plot.py ) and paste into a Python shell in terminal and works quickly and without issues.
I am trying make it executable so I can convert to .app and run from a desktop icon (and uultimately in the background... but one thing at a time)
After looking at a number of answers about making executable, I have inserted the following at the first lines:
#!/usr/bin/env python
from os import chmod
chmod +x RGB_plot.py
Initially it was only the top and bottom line. bottom line started with $ which resulted in "\u24" error, I added the middle line "from os import chmod" which eliminated "chmod not defined Pylance.... but I get the same not defined for 'x' and RGB_plot.py (perhaps because it is also the name of the script???)
Here's the script
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
sns.set_style("whitegrid", {'axes.grid' : False})
df = pd.read_excel('/Users/stanbrown/Desktop/Plot/RGB plots.xlsx')
print(df.head)
print(df.columns)
fig = plt.figure(figsize=(6,6))
ax = plt.axes(projection='3d')
ax.set_xlim(left=0)
(0.0, 1.0)
ax.set_ylim(0.0, 1.0)
ax.set_zlim(bottom=0)
(0.0, 1.0)
for i in range(len(df)):
ax.scatter3D(df['R'][i], df['G'][i], df['B'][i],
marker=df['M'][i], c=df['C'][i], alpha=0.5)
ax.set_xlabel('Red')
ax.set_ylabel('Green')
ax.set_zlabel('Blue')
plt.show()
I am new to Python and still trying to get past something more practical than copy&paste (and I do search for answers and try everything suggested before posting a question)... I have tried Laincher, VSC, Jupyter, and all either have problems each is different) or the graph plot when displayed loses the tool bar. Copy script ( RGB_plot.py ) and paste into a Python shell in terminal and works quickly and without issues.
I am trying make it executable so I can convert to .app and run from a desktop icon (and uultimately in the background... but one thing at a time)
After looking at a number of answers about making executable, I have inserted the following at the first lines:
#!/usr/bin/env python
from os import chmod
chmod +x RGB_plot.py
Initially it was only the top and bottom line. bottom line started with $ which resulted in "\u24" error, I added the middle line "from os import chmod" which eliminated "chmod not defined Pylance.... but I get the same not defined for 'x' and RGB_plot.py (perhaps because it is also the name of the script???)
Here's the script
import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
sns.set_style("whitegrid", {'axes.grid' : False})
df = pd.read_excel('/Users/stanbrown/Desktop/Plot/RGB plots.xlsx')
print(df.head)
print(df.columns)
fig = plt.figure(figsize=(6,6))
ax = plt.axes(projection='3d')
ax.set_xlim(left=0)
(0.0, 1.0)
ax.set_ylim(0.0, 1.0)
ax.set_zlim(bottom=0)
(0.0, 1.0)
for i in range(len(df)):
ax.scatter3D(df['R'][i], df['G'][i], df['B'][i],
marker=df['M'][i], c=df['C'][i], alpha=0.5)
ax.set_xlabel('Red')
ax.set_ylabel('Green')
ax.set_zlabel('Blue')
plt.show()
Share
Improve this question
edited Nov 20, 2024 at 18:17
Stainless Brown
asked Nov 20, 2024 at 16:54
Stainless BrownStainless Brown
95 bronze badges
1
|
1 Answer
Reset to default 0Save your Python script on your Desktop as RGB_plot.py
.
Now start Terminal and change the mode of your script to be executable by running:
chmod +x $HOME/Desktop/RGB_plot.py
You only need to do that once.
Now you can execute, i.e. run your script by typing the following into Terminal:
$HOME/Desktop/RGB_plot.py
If you are already in your HOME directory, you can just use:
Desktop/RGB_plot.py
If it still doesn't work, check that you have saved your script properly and not as RTF by running the following in Terminal:
file $HOME/Desktop/RGB_plot.py
and add the output to your question, along with the full Python script.
本文标签: python 3xHow to make py file executable (OSX)Stack Overflow
版权声明:本文标题:python 3.x - How to make .py file executable (OSX) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742343417a2457044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
chmod +x RGB_plot.py
from your shell not from within the python script. You likely also don't need the import then. – JonSG Commented Nov 20, 2024 at 17:30