I can't tell why this is happening but it seems to have started when I updated (everything - conda update --all). It had been about 1 year since I last had updated. Something must have changed.
Here is the script:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 3 11:25:22 2019
#author: pitosalas
"""
print("hello")
And here is the output from pressing the green triangle in spyder:
Python 3.6.6 |Anaconda, Inc.| (default, Jun 28 2018, 11:07:29)
Type "copyright", "credits" or "license" for more information.
IPython 7.3.0 -- An enhanced Interactive Python.
runfile('/Users/pitosalas/Box Sync/datawork/2019Resubmit/deleteme.py', wdir='/Users/pitosalas/Box Sync/datawork/2019Resubmit')
ERROR:root:Invalid alias: The name clear can't be aliased because it is another magic command.
ERROR:root:Invalid alias: The name more can't be aliased because it is another magic command.
ERROR:root:Invalid alias: The name less can't be aliased because it is another magic command.
ERROR:root:Invalid alias: The name man can't be aliased because it is another magic command.
hello
I met same situation today, and I checked as following.
conda create -n testenv python spyder ipython=7.3
The issue happen.
conda create -n testenv python spyder ipython=7.2.0
In this environment, it doesn't happen.
I recommend you to rebuild your environment using ipython7.2.0 or downgrade with this:
conda install ipython=7.2.0
As indicated on the issue tracker, IPython 7.7.0 sorted out this problem. I can confirm updating to 7.7.0 worked for me (conda 4.7.10 on Ubuntu 18.04, Spyder 3.3.6).
The root cause can be traced down to this commit to ipython. Downgrading to ipython=7.2.0 certainly helps. Hope this can be fixed soon.
conda install ipython=7.2.0 worked for me. ipython 7.3.0 was the culprit.
Related
After installing miniconda, my python modules stopped working, throwing ModuleNotFoundError. From what I can tell, miniconda changed my default environment settings. I checked both .bash_profile and .bashrc and updated the files to give conda the lowest priority. This fixed my default python version but didn't fix any of the broken modules.
Next I checked my PYTHONPATH with python3 -c "import sys;print(sys.path)". I discovered that the PYTHONPATH consisted entirely of conda python paths instead of the python version I had called. For reference, my default python version should be 3.8 (now set in .bashrc), and the conda version is 3.9.
['', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload']
I then manually changed my PYTHONPATH in the .bashrc file to include the appropriate library paths. After reloading .bashrc:
['', '/Users/Ghoti/venv/3.8/lib/python3.8/site-packages', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python39.zip', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9', '/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/lib-dynload']
My modules now work! However, I haven't been able to figure out how to stop the conda 3.9 libraries from being appended to my PYTHONPATH. In addition, my printed python version is wrong.
Ghoti$ python --version
Python 3.9.6
Ghoti$ which python
/Users/Ghoti/venv/3.8/bin/python
I was able to "fix" my ModuleNotFoundError problem. However, the solution is only temporary. If I ever need to switch python version/environment, I'll have to go through the process again. I'd like to figure out what is overriding my PYTHONPATH, causing it to call conda 3.9 libraries, and fix the python version irregularity. I've considered that there might be a script/process running in the background, but I haven't found any related to conda/miniconda. I've also been looking for a python setting/config file. No luck. Any suggestions on where I should look?
Edit - Did some more digging. It looks like my version 3.8 python executable was entirely overwritten, and the only existing python installation that is version 3.9.6 is in my "/usr/bin". The two conda environments have versions "3.9.12" and "3.8.13". I feel more confident the issue isn't due to conda, but unsure what could have caused the problem.
Final Edit
I don't think the problem was miniconda. I did start having problems within a few days of using miniconda and I original assumed that it just took me a while to notice the issues. However, I now think that my virtual environment was created using a shared python. Problems were noticed on the same day that I connected to network. The shared python version changed, and that broke my environment. I don't have a solution to salvage the broken environment, but rebuilding it from scratch shouldn't take too long.
Sounds like you only want to use conda when you explicitly need it, in other words, the default Python is the system Python.
If that's the case, you should disable the auto-activation of the base environment:
conda config --set auto_activate_base false
<restart shell>
Now you'll need to explicitly activate the conda environment before you can use the conda Python:
$ python
Python 3.10.6 (main, Aug 11 2022, 13:49:25) [Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ conda activate base
(base) $ python
Python 3.9.12 (main, Jun 1 2022, 06:36:29)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
I am getting acquainted with python development and it's been some time since I wrote python code. I am setting up my IDE (Pycharm) and Python3 binaries on Windows 10.
I want to start working with the pytorch library and I am used to before in python2 just typing pip install and it works fine.
Now it seems pip is not installed by default and has been replaced by something called conda?
What's the best way to install the pytorch package from the command line?
here is a screenshot link
PyTorch Documentation does have a selector that will give you the commands for pip and conda.
However, Python3 should have pip installed, it may just be pip3 (that's what it was for me).
if you have multiple version of python installed, you need to call the specific pip of that version to install for that version like
C:\Users\copperfield\Desktop>python -m pip install some_library
you can check the version by
C:\Users\copperfield\Desktop>python --version
but if you have multiples version you might need to append a number to it in order to differentiate between version so call it as python3 or python3x or python3.x where x is the specific version so for example for python 3.10 that is python310 or python3.10
Note, you can enter your python interpreter in your console by simply calling python (or python3 in your case), to get out of it simply call exit()
C:\Users\copperfield\Desktop>python
Python 3.10.4 (tags/v3.10.4:9d38120, Mar 23 2022, 23:13:41) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hello world")
hello world
>>> exit()
C:\Users\copperfield\Desktop>
the pip calls (as show previously) are to be executed in the console, not in the interpreter
I've been on macOS for 2 years now and in the past year I've begun to work a lot in Python via VScode. But lately I have been running into so many problems because I didn't set up python properly from the start. I have multiple versions and modules installed globally (I know that is bad)... But I was wondering if anyone had advice about how I can clean up the Python set up so that there is the latest version being used and all modules will be installed properly.
I used homebrew as well and that is just adding to the mess. I want to do this right so that I can stop messing with configurations every day and just be able to develop.
I'll include some basic terminal outputs but if there is more that anyone would like to see I would be happy to provide more detail. If starting from scratch is the best thing to do then I'll do it. I don't know my way around all the configuration files and pathing so I'll need some help if that is what I'll have to do.
$ which python
/usr/bin/python
$ which python3
/usr/local/bin/python3
$ python --version
Python 2.7.16
$ python3 --version
Python 3.7.7
$ python3
Python 3.7.7 (default, Mar 10 2020, 15:43:33)
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
>>> tensorflow.__file__
'/usr/local/lib/python3.7/site-packages/tensorflow/__init__.py'
VScode has the following interpreters available (not sure if that helps)
2.7.16 /usr/bin/python
2.7.16 /System/Library/Frameworks....
3.7.3 /usr/bin/python3
3.7.7 /usr/local/bin/python3
3.7.7 /usr/local/opt/python/bin/python3.7
Any help would be awesome!! I'm just tired of fighting with this and wanted to ask for help
Having multiple versions of python is not really a propblem per se.
What I recommend is :
# In $HOME/.bashrc or .zshrc
PATH=/usr/local/bin:$PATH
cd /usr/local/bin
ln -fs python3 python
# Once the first and this step done, when you type [python],
# you'll be using /usr/local/bin/python3
As the first line of your python scripts, put :
#!/usr/bin/env python
This way, you ensure your are always using the version /usr/local/bin/python3
I was installing, uninstalling and reinstalling pythons on my mac,
and I think things are screwed up a little.
At first by default, terminal ran Python 3.5 when I typed
$python
, but after doing some things, it installed 2.7 and now the terminal runs python 2.7 instead of 3.5
I installed python 3.5 form http://python.org/.
When I open up bash_profile
$vim ~/.bash_profile
This is what shows up
# virtualenv
export WORKON_HOME=~/.virtualenvs
source /usr/local/bin/virtualenvwrapper.sh
# Setting PATH for Python 3.5
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.5/bin:${PATH}"
export PATH
Now when I type:
$ python
This shows up:
Python 2.7.11 (default, Jun 23 2016, 17:25:20)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
How can I reset all the python stuff(remove older versions, etc) to the factory version that i had when I first bought Mac(python3.5)?
This worked for me:
Python 3.x
python3
Python 2.x
python
in terminal
To see what command is actually going to run when you type python at the prompt, check the top result of:
type -a python
This will list any aliases as well as taking into account the full PATH definition. To figure out why python 2 is getting precedence over python 3, be sure to check your ~/.bashrc file if it exists as well as your ~/.bash_profile.
To check your Python binaries, run:
$ which -a python python2 python3
Then check which python path comes first.
Then either set your $PATH or $PYTHONPATH (then reload your shell), or use python2 or python3 command instead.
You can also use following workaround:
PATH="/usr/bin:$PATH" ./python_script.py
where /usr/bin is pointing to the right Python binary.
I have installed python on my macbook with the python installer from Python.org. Subsequently, I went and installed pip, ipython, and numpy. Everything seemed fine. However, now I am getting the following problem. I can import numpy when I run ipython, but not when I run regular python.
E.g.
Logister-MacBook-Pro:~ Logister$ ipython
Python 2.7.6 (default, Sep 9 2014, 15:04:36)
Type "copyright", "credits" or "license" for more information.
IPython 3.1.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import numpy
In [2]: import site; site.getsitepackages()
Out[2]:
['/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python',
'/Library/Python/2.7/site-packages']
However, when I try to do the same thing in python 2.7.9:
Logister-MacBook-Pro:~ Logister$ python
Python 2.7.9 (v2.7.9:648dcafa7e5f, Dec 10 2014, 10:10:46)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
>>> import site; site.getsitepackages()
['/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages',
'/Library/Frameworks/Python.framework/Versions/2.7/lib/site-python',
'/Library/Python/2.7/site-packages']
When I try to install numpy via pip it gives me the following response:
Logister-MacBook-Pro:~ Logister$ sudo -H pip install numpy
Requirement already satisfied (use --upgrade to upgrade):
numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
It seems like python 2.7.6 understands where to find numpy, but 2.7.9 does not. Either, how can I point 2.7.9 to the right place, or how can I install numpy so 2.7.9 sees it as well?
Edit: I can run:
site.addsitedir('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python')
In 2.7.9 and then I am able to import numpy. But I dont want to do this every time I launch 2.7.9. Is there a permanent fix? Also, how do I get ipython to run 2.7.9 instead of 2.7.6?
I had a similar problem.
There is two differences versions of python installed on your computer.
Then you´ve installed numpy on python 2.7.6. but the folder of python 2.7.9 haven't numpy. Do you understand?
Other thing your macOS have a groups of variables called "Environment Variables" there it's identifying the command python with python 2.7.9.
Then if you want to use numpy with the interpreter of python do you need change the Enviroment Variables for the command "python" take the version 2.7.6 or install numpy at python 2.7.9 and work with both versions.
Good luck!
With 2 different version you must have 2 python interpreters on your machine. They are installed on different locations with different libraries. So its just right that you cannot find the module installed on interpreter A while using the interpreter B. The which command can be useful to you to figure out where those interpreter are. You can make a symbolic link manually from a folder to another but it would mess up your mind, and you probably gonna get lost later.
I recommed you to install python and ipython via Homebrew, so it would automatically do all the hard work for you.
Install homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Since you said numpy, you are probably looking for scientific stuff so:
# set up some taps and update brew
brew tap homebrew/science # a lot of cool formulae for scientific tools
brew tap homebrew/python # numpy, scipy, matplotlib, ...
brew update && brew upgrade
# install a brewed python
brew install python
Later you can run, but I recommend you to follow this tutorial:
brew install zmq
pip install ipython[all]
I was able to solve the problem by adding the following line to my .bash_profile:
export PYTHONPATH=${PYTHONPATH}:/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I then changed the Ipython version by following this stackoverflow question.