I am a novice coder and I am currently learning python and the Mac terminal.
Main Question: How do I return back to the original state of the Mac Terminal where it says Console and (base)? My mac terminal is currently on ttys000. (Both are -bash)
Originally when opening the Mac Terminal, I was presented with this:
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$
However, currently, when opening the Mac Terminal, I am presented with this:
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$
Why is this occurring?: I was attempting to make my python code become an application via py2app. This did not work so I tried converting the python script into a DMG file. Here are some of the tutorials I attempted to follow:
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
Why I am looking to get this fixed?: When the Mac terminal was in its original state with Console and (base), it recognized my pip imports for PIL, mplfinance, pandas_datareader, and yahoo_fin. Now when the mac is on ttys000, PIL, mplfinance, pandas_datareader, and yahoo_fin are no longer recognized as module names. In the mac terminal, after attempting to run the program (the name of my vscode python script is called V1_terminal, I am presented with this:
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
My program is stored in vscode with python 3.8.8 64-bit ('base': conda) Thus, I am unable to run the code.
In vscode, in python, this is my import lines of code:
#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
Thank you so much in advance for offering advice and helping me! If I should add more context please let me know. Thank you!
Updates:
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$
So what I ended up doing is deleting Anaconda-Navigator from my Macbook then attempted to redownload it but ran into the error:
Anaconda3 is already installed in /opt/anaconda3. Use 'conda update anaconda3' to update Anaconda3.
So I used the answer found in this StackOverflow post and punched it into the Mac Terminal and successfully redownloaded the Anaconda-Navigator:
Anaconda-Navigator Error
I reinstalled mplfinance, yahoo_fin, etc via pip in the Mac Terminal and my python code successfully runs! The Terminal is still on ttys000 (and not Console like originally) but I am successfully running code. Feels like a rudimentary way to solve this but seems like everything is okay now. Thank you to you all for your time helping me!
here is what you can do:
Setup a virtual env
python3 -m venv venv
source venv/bin/activate
pip install tk numpy yahoo_fin mplfinance pandas pandas_datareader requests matplotlib
Optionally save the requirements into a file.. "pip freeze > requirements.txt" and check it in with your code. Next time you can do "pip install -r requirements.txt"
Now run your program.
Setting up a venv is a one time thing.. next time you open a new terminal, just activate the venv
source venv/bin/activate
you now are inside an environment which has your packages installed..
Related
I am trying to make a nmap scanner for the InfoSec Certification on freeCodeCamp.org and cannot get Visual Studio Code to recognize that I have installed nmap. I am very beginner and in the process of learning.
from cProfile import run
import nmap
scanner = nmap.PortScanner()
print("Welcome, this is a simple automattion tool")
print("<------------------------------------------->")
When I run this in VS Code I get the following in the terminal:
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1> python3 scanner.py
Traceback (most recent call last):
File "C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1\scanner.py", line 2, in <module>
import nmap
ModuleNotFoundError: No module named 'nmap'
PS C:\Users\mjame\OneDrive\Documents\Jim\Coding\fcc_python_for-pen_testing\nmap_scanner_1>
I have so far:
Updated to the current Python 3.10.7
Installed Nmap the first time from https://nmap.org/ for Windows
Uninstalled Nmap
Reinsalled Nmap using >>>pip3 install python-nmap
For future searchers (as in my comment above), if you installed a module with pip3 but are still getting module import errors, try python3 -m pip install <module-name>.
Not sure how/why this happens (pip3 installing somewhere that python3 is not looking for modules - maybe PYTHONPATH-related), but the above can [usually] help.
It seems that Python cannot find nmap module.
You can either add it to path in Windows via Start -> Edit system environment variables -> Environment variables... and then edit PATH VARIABLE by adding at the end path to nmap module that you have installed or move the module to default Python modules directory which should be C:\Users\YourLogin\AppData\Local\Programs\Python\Python310\Lib\site-packages
The import works when I call it from the command line, but when I call the import in the ipynb I get the following error:
ImportError: libmkl_intel_lp64.so: cannot open shared object file: No such file or directory
I have already added the path to libmkl_intel_lp64.so to my bashrc file, so I am not sure what else I can do to fix this import error in the notebook.
Your command line python interpreter,
and your jupyter notebook kernel,
have different environments.
Use one of these techniques to help you debug the path problem:
$ python -m site (from bash prompt)
import sys; from pprint import pp; pp(sys.path) (within a cell)
Do yourself a favor, and use conda to manage your environment.
https://docs.conda.io/en/latest/miniconda.html
Be sure to conda activate myfavoriteenvironment
before you start the jupyter kernel.
Mac OS VSCode built-in terminal can't import installed python packages.
I've installed NumPy correctly using Anaconda in one of my environments called tf20;
And then I created a python script scene.py
import numpy as np
print(np.__version__)
I can run this script in my system Terminal like:
(tf20) mac#Macbook:~/Desktop/manim_project$ python scene.py
1.18.5
However, an import error occurred when I run the same script.
(tf20) mac#Macbook:~/Desktop/manim_project$ python scene.py
Traceback (most recent call last):
File "scene.py", line 10, in <module>
import numpy as np
ImportError: No module named numpy
However, when I run this by pressing F5, the debug mode, the problem disappeared.
(tf20) mac#Macbook:~/Desktop/manim_project$ cd /Users/mac/Desktop/manim_project ; /usr/bin/env /Users/mac/.jackprogram/anaconda3/envs/tf20/bin/python /Users/mac/.vscode/extensions/ms-python.python-2021.11.1422169775/pythonFiles/lib/python/debugpy/launcher 62372 -- /Users/mac/Desktop/manim_project/scene.py
1.18.5
(tf20) mac#Macbook:~/Desktop/manim_project$
I think I selected the right python environment tf20 in VSCode because
the VSCode built-in terminal showed (tf20) at the beginning of the terminal prompt.
the left corner of VSCode showed Python3.7.7 64-bit ('tf20:conda').
and I even used cmd + shift + p then Python: Select Intereter to ensure I selected the right python environment.
Because of this problem, I have to use the macOS terminal application to run the Python scripts for a half year.
Help. Please!
I am using python3.
I installed twython on my MAC using pip3 command and I confirmed it was successfully installed.
When I run my python file, it comes up with:
ImportError : No module named twython
My code is as follows:
import sys
import string
import json as simplejson
from twython import Twython
I can't comment the response from #ajxs, but as additional information to his repsonse:
You can change the default python interpreter like this in your MAC terminal:
nano ~/.bash_profile
Add this to the file:
alias python=python3
exit the the bashrc file and run the following command:
source ~/.bash_profile
Now you can check the defaul python version with:
python --version
Maybe this helps you.
First thing that springs to mind is to check that you're running the script with the correct version of Python. Use python --version on the command line to check which version of Python you're executing by default. I've definitely had problems like this before when I've forgotten that my system's default version was 2.7 and I needed to use python3 to run Python 3 on the command line.
I have an account in a CentOS server without sudo permission. As a result, I tried to install IPython from source code by python setup.py prefix=<my home directory>.
However, I got the Error:
Traceback (most recent call last):
File "/usr/bin/ipython", line 19, in <module>
from IPython.frontend.terminal.ipapp import launch_new_instance
ImportError: No module named IPython.frontend.terminal.ipapp
I found a question same to mine: IPython import failure and python sys.path in general.
I followed the asker's instruction to add the directory of my IPython to the IPython execution file.
#!/usr/bin/python
"""Terminal-based IPython entry point.
"""
import sys
sys.path.append("./Ipython directory")
from IPython.frontend.terminal.ipapp import launch_new_instance
launch_new_instance()
However, I got the same error as well. So I want to know how can I launch IPython correctly? Thanks.
You probably want to install with the --user flag, which should put it on sys.path automatically.
python setup.py install --user
If you need to use --prefix for some other reason, then make sure that the directory you add to sys.path is the folder containing the IPython package, not the IPython directory. It will probably end with 'site-packages'.
I copied the IPython source folder into ~/bin/. The execution file of IPython can recognize the module in IPython and the IPython shell launches successfully.