Python 2.7.1 can't see Twisted - python

I have a new MacBook Pro running OS X 10.6.6 / Snow Leopard -- which ships with Python 2.6, although I have installed 2.7.1
Unfortunately, this doesn't seem to see the Twisted install in the 2.6/Extras/lib/python/twisted directory, as I find I'm unable to import modules that I can see are present in that directory.
"which python" returns "/Library/Frameworks/Python.framework/Versions/2.7/bin/python"
and running python returns the same: "Python 2.7.1 (r271:86882M, Nov 30 2010, 10:35:34)"
I have added the twisted directory (absolute) to sys.path, and I have added it to .bash_profile, which now consists of the following:
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}"
PATH=$PATH:/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/twisted
export PATH
Any ideas how I can get 2.7.1 to see the Twisted install? Or am I trying to do something that just can't be done?
thanks.

You'll need to install Twisted into your Python 2.7 installation somehow. The "2.6" in that path should be a hint that you shouldn't be trying to tell Python 2.7 about it. Among other things:
Extension modules are not compatible between python versions. You may get a segfault if you try to use them.
Bytecode formats are not compatible between python versions. Python will fall back to parsing '.py' files, which is slower.
If you're using an operating system that ships with Python 2.6, there is a good chance that the version of Twisted included is not compatible with Python 2.7, since Python 2.7 may not have been out yet when it was released.

You'll have to install twisted using python 2.7.
Also, python doesn't look up what's in the PATH variable for imports, it looks in PYTHONPATH. But just putting your python 2.6 folder in your pythonpath isn't a very good solution.

Create an environment using virtualenv.
Install Twisted in your newly created environment using pip.

You need to set up an environment for your new Python 2.7 or use the OS installed 2.6.
OS X ships with NumPy for example, but your new Python 2.7 will not 'see' it.
The best solution (IMHO) is this:
o Don't change the OS default Python AT ALL!
o Install Python 2.7, 3.0 as you wish with the system Python first in the path
o Use virtualenv to set up a personal Python environment -- a sandbox. Install twisted into that.
o Install libraries into the environment you are going to use for the job. Might mean duplicates.
o Use your shebang to execute the proper Python

Related

How to remove python 2.7 from Mac OS X 10.14.5?

I realise that there is already an answer for the question but its for Mac OS X 10.6.4 and the python he installed was from "python.org". My python 2.7 has come built-in in my Mac so how do I remove it? Is there any way of removing it? I have installed a python3.7 from the website and it is working perfectly but 2.7 is also working. I want to remove 2.7 and make it such that when i type "python" in terminal it runs python3.7 and not 2.7.
You don't have to remove python 2.7. You can simply add the command as an alias (you can also add this in your ~/.bash_profile file):
alias python='python3.7'
Do not remove python 2.7 (default python package), it may damage your operating system.
If you want you can simply use this command (removes the python installed with homebrew):
brew uninstall python
Refer this question if you really thinking of removing python 2.7. Here is another question which will give you more information.
the 2.7 version of python is a bundle that comes along with the MAC Unix operating system. which means maybe you not using it but there are some pre-loaded programs and dependencies which uses python hence you cannot remove it completely. If you want to use python 3 directly from the terminal's command line just use "python3" in place of "python". this will launch python 3.* what ever you have installed.
A Mac has more Pythons than a Malaysian jungle.
A new Mac M1 has version 2.7 in /System/Library/Frameworks/Python.framework/Versions/2.7
If you use Homebrew to install Vim, it uses /opt/homebrew/Cellar/python#3.9, and it warns you if you delete it, Vim won't work.
Meantime, I want to do the introductory tensorflow machine learning course, and it insists on Python 3.8
So in my .bash_profile
alias python='/opt/homebrew/Cellar/python#3.8/3.8.8_1/bin/python3'
alias python3='python'
alias python3.8='python3'
and I deleted all references to Python2.7.
But when I open a new terminal, and run a Python program which does
print(sys.path)
it includes /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7
and tensorflow won't work. The Mac is inserting its own Python into what I want.

how to update python 2.7 to python 3 in linux?

My OS is CentOS 7.0. It's embedded python version is 2.7, and I want to update it to Python 3.4.
when input the
print sys.path
output is:
['', '/usr/lib/python2.7/site-packages/setuptools-5.8-py2.7.egg',
'/usr/lib64/python27.zip', '/usr/lib64/python2.7',
'/usr/lib64/python2.7/plat-linux2', '/usr/lib64/python2.7/lib-tk',
'/usr/lib64/python2.7/lib-old', '/usr/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7/site-packages',
'/usr/lib64/python2.7/site-packages/gtk-2.0',
'/usr/lib/python2.7/site-packages']
So, if I download the python 3.7, then ./configure , make , make install. Will it override all the python-related files ? Or if I use the
./configure --prefix=***(some path)
then is it safe to remove all the old python files or directory?
In a word, hope someone gives me instructions about how to update to python 3 on linux. Thanks a lot.
Python 2 and 3 can safely be installed together. They install most of their files in different locations. So if the prefix is /usr/local, you'll find the library files in /usr/local/lib/pythonX.Y/ where X.Y are the major and minor version numbers.
The only point of contention is generally is the file python itself, which is generally a symbolic link.
Currently it seems most operating systems still use Python 2 as the default, which means that python is a symbolic link to python2. This is also recommended in the Python documentation.
It is best to leave it like that for now. Some programs in your distributions may depend on this, and might not work with Python 3.
So install Python 3 (3.5.1 is the latest version at this time) using your favorite package manager or compiling it yourself. And then use it by starting python3 or by putting #!/usr/bin/env python3 as the first line in your Python 3 scripts and making them executable (chmod +x <file>).
Python 2.7 Files are most likely still used by the OS and are therefore not safe to remove!
You can just run python3 using the
python3 [option]
command where option can be what you want to execute or how. or if you leave it blank you enter the python3 console.
Upgradeing your python2.7 to python3 is therefore not possible you will have to install python3 manually.

install new version of python

I have mac os x, recently I have install python version 3.2 before I had version 2.6.1. but when I type "python" in terminal it prints Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49). what does it mean? how can I use python 3.2 that have install this week?
I'm on windows, but I'm hoping the solution will work cross-platform.
Your computer has something called environment variables. Basically, a list of locations with names on them like python installation path. Windows computers, and probably Mac ones too, use these to intercept commands in the terminal.
Likely, python is an environment variable in your machine but it points to your python-2.6.1 installation.
From what I'm reading, you can edit your environment variables at /etc/launchd.conf, re-assigning your environment variable python to point at Python 3.2 instead of Python 2.6.1.
I hope this works for you; I don't have Mac OS X, so I can't easily help you navigate or know what you're looking at! But, good luck!
And Happy Coding!
EDIT: Here's some more information about environment variables in OS X!
instead of using python I typed python3 in terminal and it was the solution

python path error

I had two version of python.. python 2.6 and python 2.7
I just now deleted python 2.6 (rather in very unsafe way)..
Now when I type python, I get this error:
python: VERSIONER_PYTHON_VERSION environment variable error (ignored)
python: posix_spawn: /System/Library/Frameworks/Python.framework/Versions/2.6/Resources/Python.app/Contents/MacOS/Python: No such file or directory
My python 2.7 is installed in
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
When i do which python
I get /usr/bin/python
How do i resolve this mess I have created.
Looks like you deleted the Apple-supplied Python 2.6. You shouldn't have done that. Never delete files in /usr, other than /usr/local, or in /System/Library. When you install another framework version of Python, like you did with the Python 2.7 into /Library/Frameworks, the way to manage which one you use is by managing your shell PATH environment variable, not by attempting to modify /usr/bin/python. You have three primary options now: (1) live without the Apple-supplied Python 2.6 until your next OS X upgrade and hope that no other Apple-supplied utilities you need depend on it; or (2) reinstall all of OS X; or (3) if you remember exactly what you deleted and have a full backup, attempt to restore the deleted files. To use the newer Python 2.7, put it first on your path, for example:
export PATH=/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH

How do I 'down grade' to python2.7

Being quite cavalier I went for the latest version of Python (3.2.2)
Unfortunately it lacks the matplotlib that I desperately need.
I have downloaded python 2.7.
My simple question is weather I have to uninstall python3.2 or can I leave it on my windows 64 system?
you can keep the python 3.2 installation, but you will have to be carefull about which version you launch (by making the call explicit). you can always check the python version in a script by doing:
import sys
print sys.version
If you have no particular use of python 3.2, I recommend uninstalling it.
I'm not sure if there's a difference on python in windows but on mac and linux I simply call older versions using
python2.6 or python2.7
It seems to keep all the versions I previously had before. Maybe try running the above command and seeing if it works on windows and if it does just change the symbolic link 'python' is pointing to.

Categories

Resources