我是一名新手編碼員,目前正在學習 python 和 Mac 終端。
主要問題:我如何回傳到顯示控制臺和(基本)的 Mac 終端的原始狀態?我的 mac 終端目前在 ttys000 上。(兩者都是-bash)
最初在打開 Mac 終端時,我看到了這個:
Last login: Sat Jan 5 13:30:29 on console
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
(base) Myusernamehere-MacBook-Pro:~ Myusernamehere$
然而,目前,當打開 Mac 終端時,我會看到:
Last login: Sat Jan 8 19:18:51 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Myusernamehere-MacBook-Pro:~ Myusernamehere$
為什么會發生這種情況?:我試圖通過 py2app 使我的 python 代碼成為一個應用程式。這不起作用,所以我嘗試將 python 腳本轉換為 DMG 檔案。以下是我嘗試遵循的一些教程:
- https://www.youtube.com/watch?v=kSw4_lMqR3M
- https://www.youtube.com/watchv=DVOoHL2Bp_o&list=PL5RJRIWAZ174f_lkWRkjk3nFCEZs_VBFa&index=13&t=198s
- https://www.youtube.com/watch?v=IIAlkQEw8Gc
為什么我要解決這個問題?:當 Mac 終端在其原始狀態下使用 Console 和 (base) 時,它識別出我對 PIL、mplfinance、pandas_datareader 和 yahoo_fin 的 pip 匯入。現在當 mac 在 ttys000 上時,PIL、mplfinance、pandas_datareader 和 yahoo_fin 不再被識別為模塊名稱。在 mac 終端中,嘗試運行程式后(我的 vscode python 腳本的名稱稱為 V1_terminal,我看到了這個:
Myusernamehere-MacBook-Pro:Stock_Market Myusernamehere$ python V1_terminal.py
Traceback (most recent call last):
File "V1_terminal.py", line 4, in <module>
from PIL import ImageTk, Image
ImportError: No module named PIL
我的程式使用 python 3.8.8 64-bit ('base': conda) 存盤在 vscode 中因此,我無法運行代碼。
在 vscode 中,在 python 中,這是我的匯入代碼行:
#imports for GUI
import tkinter as tk
from tkinter import *
from PIL import ImageTk, Image
import os
from numpy import loads, place
# for Yahoo Finance
from yahoo_fin.stock_info import *
import yahoo_fin.stock_info as yaf
import mplfinance as mpf
# for data series and plot
from pandas_datareader import data
from datetime import datetime, timedelta
import pandas as pd
import numpy as np
import requests
import matplotlib.pyplot as plt
非常感謝您提前提供建議和幫助!如果我應該添加更多背景關系,請告訴我。謝謝!
更新:
I tried conda activate in the terminal window and this is the result:
Last login: Mon Jan 10 13:13:22 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Myusernamehere-MacBook-Pro:~ Myusernamehere$ conda activate
-bash: /opt/anaconda3/bin/conda: /opt/anaconda3/bin/python: bad interpreter: No such file or directory
Myusernamehere-MacBook-Pro:~ Myusernamehere$
I tried conda config --set auto_activate_base true and this is the result:
Last login: Mon Jan 10 16:11:40 on ttys000
The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
Myusernamehere-MacBook-Pro:~ Myusernamehere$ conda config --set auto_activate_base true
-bash: /opt/anaconda3/bin/conda: /opt/anaconda3/bin/python: bad interpreter: No such file or directory
Myusernamehere-MacBook-Pro:~ Myusernamehere$
uj5u.com熱心網友回復:
所以我最終做的是從我的 Macbook 中洗掉 Anaconda-Navigator,然后嘗試重新下載它,但遇到了錯誤:
Anaconda3 已經安裝在 /opt/anaconda3 中。使用“conda update anaconda3”更新 Anaconda3。
所以我使用了在這個 StackOverflow 帖子中找到的答案并將其打入 Mac 終端并成功重新下載了 Anaconda-Navigator:
Anaconda-Navigator 錯誤
我通過 Mac 終端中的 pip 重新安裝了 mplfinance、yahoo_fin 等,我的 python 代碼成功運行!終端仍在 ttys000 上(而不是最初的控制臺),但我成功運行代碼。感覺像是解決此問題的基本方法,但現在似乎一切正常。感謝大家花時間幫助我!
uj5u.com熱心網友回復:
這是你可以做的:
- 設定虛擬環境
python3 -m venv venv
source venv/bin/activate
pip install tk numpy yahoo_fin mplfinance pandas pandas_datareader 請求 matplotlib
可選擇將需求保存到檔案中。“pip freeze > requirements.txt”并使用您的代碼將其簽入。下次你可以執行“pip install -r requirements.txt”
現在運行你的程式。
設定 venv 是一次性的事情.. 下次打開新終端時,只需激活 venv
source venv/bin/activate
你現在在一個安裝了你的包的環境中..
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/408693.html
標籤:
