I know this may be the most silliest questions to be asked but i'm suddenly not able to open python from terminal.
I have python 2.7 installed on ubuntu 14.04 box, but now when i fire python on my command line i get the error
aman#L-JZCHG32:~$ python
The program 'python' is currently not installed. You can install it by typing:
sudo apt-get install python-minimal
I have tried reinstalling python
sudo dpkg -P python2.7
sudo apt-get install python2.7
but it still wont work. Can somebody suggest me what went wrong and how can i correct it.
Thanks.
It seems you've probably corrupted your PATH variable. Try /usr/bin/python in the terminal. If that works, you'll need to fix your PATH variable.
A quick fix would be export PATH=/usr/bin:$PATH but there's probably something not quite right with the whole path variable at the moment, which would be worth further examining.
Related
I am trying to write a port scanning program as part of my course assignment. However, even after downloading Nmap, an error appeared. It says 'nmap' is not accessed by pylance. I cannot access it interactive mode either. I am still very new to programming so any form of help will be much appreciated
As you can see here Nmap is already downloaded.
But...
And...
I tried deleting and re-installing Nmap, that did not work. I searched YouTube for solutions, but a lot of the files and programs they had I did not. I have already downloaded nmap from the website too.
Maybe that happened because you have many interpreter and you installing in another interpreter to fix that you need to change the interpreter you can see the documentation in
https://code.visualstudio.com/docs/python/environments
or you can try using python venv by write this command in your terminal
python -m venv venv
after that activate the venv and activate the venv
.\venv\Scripts\activate
after you activate the venv you just need to install the nmap
pip install python-nmap
I hope this answer can solve your problem
You might have multiple version of python installed. When you run py is opens up 3.10.7 for you. You need to make sure you installed python-nmap for that version.
Apart from using a virtual environment, a quick fix would be to try installing nmap using pip3
pip3 install python-nmap
This will install nmap for your python3 installation. However if you have multiple python3 installations, I would suggest using a virtual environment of the particular python version you want.
Suddenly I cannot run ansible.
Whenever I try any ansible command like ansible-playbook, ansible version, etc. it shows error
`/Users/myusername/Library/Python/2.7/bin/ansible: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/: bad interpreter: No such file or directory`,
Even if I let ansible run different python version, like ansible-playbook --version -e 'ansible_python_interpreter=/usr/bin/python3, it shows the same error.
FYI: which ansible returns /Users/myusername/Library/Python/2.7/bin/ansible
I guess it is related to my recent installation of python. Since I installed a python3.10 recently, The python2.7 becomes not work. Note I did not remove anything about python2.7 myself. looks like the installation of python3.10 changed python2.7 setting.
For most other application, I now pointed the system to use python3 as workaround, e.g. I set CLOUDSDK_PYTHON=/usr/bin/python3 to make accessing cloud cli works again. But for Ansible, I have not figured out how to make it work. I am using MacOS terminal.
Does anybody know how to resolve the above issue so that I can run ansible again? Anyway is OK as long as I can run ansible. Either reinstall ansible and let it use python3 instead of using Python2.7 or guide me how to reinstall python2.7 (in a right way, not messy with python3.10, currently I am scared of installing python, I am afraid if I reinstall python2.7, both python3.10 and 2.7 will be out of work then I cannot work).
Please help. Thanks.
You will have to do some cleanup on your system because somehow, Python 2.7 was removed from you system. This might have happened due to updating to macos 12.4 Monterey at some point, because Monterey 12.3 and newer removed the system-provided Python 2.7, replacing it with a Python 3.8.9 installation (/usr/bin/python3).
However, you still have stuff in your environment that reference all those Python 2.7 things, like your ${HOME}/Library/Python/2.7/bin/ansible directory.
Here are the things you can do to (hopefully) make ansible and your environment work again.
Change your shell's PATH environment.
You're probably using zsh since it's the default shell on macos. Have you ever changed your .zshrc or other environment files to add /Users/<name>/Library/Python/2.7/bin in your PATH? You will need to remove that.
Additionally, if you strictly want to use the Python 3.10 you manually installed (and not Monterey's system-provided /usr/bin/python3 which is python v3.8.9), you will probably need a PATH that looks like this...
# somewhere in your ~/.zshrc, probably near the bottom
export PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
Re-install Ansible
With whatever python3 binary you're using, re-install ansible
python3 -m pip install --user ansible
This will end up installing ansible into ${HOME}/Library/Python/<VERSION>/bin
Update PATH again to include new bin dir
Building on part (1) above, you want to include the bin directory for Python stuff in your user directory, to be able to refer to anything installed by pip install --user.
# somewhere in your ~/.zshrc, probably near the bottom
export PATH="${HOME}/Library/Python/3.10/bin:${PATH}"
export PATH="/Library/Frameworks/Python.framework/Versions/3.10/bin:${PATH}"
Reload your shell and try to run ansible
# if you already have a shell open, run this
# to reload your zsh configs
exec zsh
# hopefully this returns the correct path!
which ansible
# and hopefully this runs!
ansible --help
Reinstall Anything Else You Need
You reference stuff like CLOUDSDK_PYTHON which sounds like you also have stuff like the gcloud module installed. Time to reinstall those with your new Python.
python3 -m pip install --user gcloud
# and whatever else needs reinstalling
Hopefully this all fixes your environment. Now you can clean up the remnants of Python 2.7 stuff from your home directory once everything else is working, as this directory has broken module installs that reference a deleted system Python anyway.
cd ~/Library/Python
rm -rf 2.7
I used: "sudo apt-get install idle3" and "sudo apt install idle" in my attempts to install Python IDLE from the terminal. Both worked fine, with a successful installation message afterwards. However, when I type $ idle or $ idle3, nothing happens. When I tried to open it from the "Applications" menu, it also would not open. (Note: I can set up a python file and run it without trouble, so I am sure that both Python2 and 3 are properly installed.) Any suggestions on how to make IDLE run correctly, or maybe to reinstall it a different way so that it actually opens?
I installed virtualenv using the command sudo pip install virtualenv and the installation is successful. Later, when I type virtualenv, I get the error message as following, -bash: virtualenv: command not found
The virtualenv is installed in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. I see the similar questions in the forum with no definitive answers.
Python is in the location /usr/local/bin/python and I have version 2.7.9. I get the following using ls -l command,
Why do I see the virtualenv is not found and how to solve the issue ?
UPDATE:
I use the command
ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py to put the virtualenv.py
inside the /usr/local/bin folder. Previously, I only did the same for the virtualenv file. Now, when I put the command virtualenv in the terminal, I get
-bash: /usr/local/bin/virtualenv: Permission denied.
I later use
sudo ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv.py /usr/local/bin/virtualenv.py
and the say message keep showing. which virtualenv still returns nothing.
Pursuant to #Jason's suggestion, try making the symbolic link for virtualenv in the /bin directory like so:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/virtualenv /usr/local/bin/virtualenv
Why don't re-install virtualenv? Also try to use the latest version of pip (sudo pip install -U pip).
Not sure if the answer will be useful to you, as i see the question is a few month old, but maybe it will be helpful for others.
I encountered the same problem, after installing python3.5 and pyCharm on my Mac. I moved the 3.5 folder from /Library/Frameworks/Python.framework/Versions/3.5 to /System/Library/Frameworks/Python.framework/Versions/3.5, following this guide, after disabling the System Integrity Protection first with reboot into recovery mode (boot with ctrl+R), and executing csrutil disable in the terminal. After reboot it was possible to move the python3.5 folder, and then i followed the guide, and everything worked like charm. In pyCharm i could choose the version 3.5 from /System/... instead of /Library/... (however, i still left a soft link in /Library/... to the /System folder where the python3.5 now was, just in case), and after adding the path to my zsh i could execute pip3 install virtualenv. So far so good.
Next, i tried to create the environment with virtualenv -p python3 env, and here i had the same problem as you. It seemed like the path could not be added somehow. Initially i also tried to look in the /System/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/ and include it in the $PATH, then also create softlinks to virtualenv.py as you tried too, but finally found that although all the files are in the site-packages folder, the actual executable was in /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv. As the path there was included in my $PATH, i have no idea why it did not execute when typing virtualenv -p python3 env, even with sudo as you tried too, but once i typed the full path /System/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv -p python3 env, it worked like charm again.
I still have no idea why, but it worked and now i can move on :)
Hope it helps, and hope someone can explain this better than me.
You are created the symbolic link to the wrong file. As far as I know virtualenv is installed to /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv, (you can change the numbers for your Python version) so the command for creating the symbolic link should be:
ln -s /Library/Frameworks/Python.framework/Versions/2.7/bin/virtualenv /usr/local/bin/virtualenv
In attempting to get started learning and developing python, I've tried to follow the Python Guide to installing python on OS X, but haven't found it particularly "noob friendly." I have a new MacBook (Mtn. Lion - OS X 10.8.3) wich comes with Python 2.7.2 built in. But the guide advises installing a "framework-style build" via homebrew. So:
I installed homebrew via ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Then it tells you to add homebrew to the top of your PATH by adding it to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc file in my home directory. After searching Stack Overflow on how to do that, I ran nano ~/.bashrc, and inserted the line export PATH=/usr/local/bin:$PATH to the file and saved the file.
I then ran brew install python --framework and the install completed.
Then, the guide says to "add the new Python scripts directory to your PATH" so, I'm assuming that means I need to add the line it provides to my ~/.bashrc file also. So, I added export PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my previous entry.
Finally, this is where I run into trouble, it says to easy_install pip. However, when I do that I get an error 13.
So, here are the things I need some help with.
Was I correct in my assumptions about how to add homebrew and python scripts to my PATH?
Did I do something wrong or do I just need to use sudo to install pip? (I'm really sorry if the answer is already on this page but even those answers don't make total sense to me and I want to be careful and not screw something up)
After installing the framework-style build of python (which I believe was the current 2.7.3), how come running python in my terminal still shows v2.7.2?
Thanks! I appreciate any help.
I've tried to follow the Python Guide to installing python on OS X,
but haven't found it particularly "noob friendly.
Yes, I think it is misleading/outdated.
Then it tells you to add homebrew to the top of your PATH by adding it
to your ~/.bashrc file. ls -a showed that I did not have a ~/.bashrc
file in my home directory. After searching Stack Overflow on how to do
that, I ran nano ~/.bashrc, and inserted the line export
PATH=/usr/local/bin:$PATH to the file and saved the file.
On the Mac, just use ~/.profile
I then ran brew install python --framework and the install completed.
I think you don't need the --framework option unless you want to replace your Mac OS default installation and need an Mac OS Framework-style directory layout. There is no need to replace it though, the homebrew installation will take precedence anyway.
Then, the guide says to "add the new Python scripts directory to your
PATH" so, I'm assuming that means I need to add the line it provides
to my ~/.bashrc file also. So, I added export
PATH=/usr/local/share/python:$PATH to my ~/.bashrc file above my
previous entry.
Again, do it in ~/.profile. And don't forget to do a
source ~/.profile
otherwise the changes will only become active in any new terminal window, not the one you are currently using.
Finally, this is where I run into trouble, it says to easy_install
pip. However, when I do that I get an error 13.
The error shows that you try to install it your Mac OS system's default Python library (rather than in /usr/local, homebrew style), which would require root privileges. Just don't.
Also, with homebrew python, pip is already installed.
Check your path:
$ which pip
/usr/local/bin/pip
$ ls -l /usr/local/bin/pip
[..] /usr/local/bin/pip -> ../Cellar/python/2.7.3/bin/pip
Added bonus: Then do
pip install virtualenv
and use that.
And to your questions:
Was I correct in my assumptions about how to add homebrew and python
scripts to my PATH?
Yes, but use .profile and do a source .profile afterwards.
Did I do something wrong or do I just need to use sudo to install pip?
(I'm really sorry if the answer is already on this page but even those
answers don't make total sense to me and I want to be careful and not
screw something up)
You don't need sudo with homebrew, and pip is installed automatically with homebrew python.
After installing the framework-style build of python (which I believe
was the current 2.7.3), how come running python in my terminal still
shows v2.7.2?
Probably PATH not correct, do echo $PATH and check that it is correct. That is unrelated to being "framework-style" or not, though.
If you installed python with homebrew, you should already have pip installed. Try running
pip --version
to see whether and where pip is installed. Hopefully it's in a /usr/local/... path where your other homebrew things live.
Also before you install too much more with homebrew be sure to run these commands:
brew update
brew doctor
Good luck!