I'm trying to use pypy compiler to run my python code but the sys.path for pypy is different from normal python compiler so when I tried to import default modules such as
import pygame
it fails in pypy, stating that the module is not found, while it works correctly with the normal python command. Any help is greatly appreciated.
I think you're expecting any module installed for CPython to work with PyPy out of the box. That's not the case. It's the same when you upgrade from CPython 2.6 to CPython 2.7: the modules you have already installed for 2.6 are not automatically available for 2.7, and must be re-installed. Similarly, you must re-install the modules for PyPy.
This said, the standard pygame doesn't work too well with PyPy, but stay tuned; it seems someone is working on a version of pygame based on cffi, which should work very well with PyPy.
Related
My question is if there is a difference between a python module compiled in python3.7 to the same module compiled in other Python3 sub-version?
I work in an environment in which I don't have pip to install modules so I have to compile the modules myself. I wonder if today I'm compiling a module with Python3.7, will it work tomorrow when I'll upgrade to Python3.8 or downgrade to Python3.6
Thanks is advance
Python is (infamously) really not a compiled language but an interpreted one. One notable caveat to this is that the Python interpreter will cache modules with .pyc files. Here is a more comprehensive summary of those modules. Of course if you're using py2exe, PyInstaller, or some other ad-hoc compiler then its possible that freezing the package as an executable will make it fragile to version changes.
Generally though, in between similar versions (e.g. 3.6 to 3.8) the changes to the standard library are small. If your package (or its dependencies) use some feature that has changed then you can expect it to no longer work and you'll need to update that part of your code. This is the changelog comparing features from 3.6 to 3.7 and the list of backwards incompatible changes is short:
async and await are now reserved keywords.
This is the changelog comparing 3.7 to 3.8 and it has some more subtle differences.
I run a script on several CentOS machines that compiles Python 2.7.6 from source and installs it. I would now like to update the script so that it updates Python to 2.7.12, and don't really know how to tackle this.
Should I do this exactly the same way, just with source code of higher version, and it will overwrite the old Python version?
Should I first uninstall the old Python version? If so, then how?
Sorry if this is trivial - I tried Googleing and searching through Stack, but did not found anyone with a similar problem.
Replacing 2.7.6 with 2.7.12 would be fine using the procedure you linked.
There should be no real problems with libraries installed with pip easy_install as the version updates are minor.
Worst comes to worst and there is a library conflict it would be because the python library used for compiling may be different and you can always reinstall the library which would recompile against the correct python library if required. This is only problematic if the library being installed is actually compiled against the python library. Pure python packages would not be affected.
If you were doing a major version change this would be okay as well as on CentOS you have to call python with python2.7 and not python, so a new version would call with python2.8
I basically use python 3.4 and the numpy 1.3.0 had been installed and launched successfully on my windows machine.
Recently, I've just installed python 2.7, in order to use Brian2 library, but I've an error in traceback as Importing numpy failed: No module named numpy, whereas it has been installed and works well under aegis of python 3.4
Actually, when I switch the interpreter address to python 2.7, the problem will be happened, in which the numpy is totally hidden in view of the python 2.7...
Any help?!
Edit:
I even tried to choose python 2.7 (As it was detected automatically in registry), within the re-installation of numpy... but still there is nothing as the installed package in Python Interpreters -> Python 2.7
Python x.y (on Windows) generally expects to find 3rd party modules and packages in .../pythonxy/Lib/site-packages. If the module or package is pure python code that is compatible with multiple python versions (such as code that works with 2.6 and 2.7, or 3.3 and 3.4, or much more rarely 2.7 and 3.4), then it is possible to access one copy of the package from multiple site-packages directories. (This is done with x.pth files, which is another topic not relevant here.)
However, on Windows, anything compiled from C must be compiled for Windows and a particular version of Python, including 32 versus 64 bits. (This is currently a requirement of Microsoft C, which may change in the future.) To run with 3.4.x, you installed numpy-1.3.0-for-3.4-winxx. To run with 2.7, you must install numpy compiled for 2.7.
By the way, current numpy is 1.8, with 1.9 due soon. You might want to take the opportunity to upgrade. If you have trouble getting Windows binaries for python extensions, gohlke's site is excellent.
I had PyQt4 running fine with python2 on Ubuntu 12.04. I then installed python-PySide. But the installation test would give me a module not found error. Then I installed python3-PySide and it works fine. So obviously something to do with my environment paths, but I'm not sure what I need to do. I'm guessing PySide is automatically checking if python3 exists and if it does then it'll use it regardless. I need PySide to work with python2.7 because of Qt4.8 compatibility issues. Any suggestions?
some info about my system:
which python
/usr/bin/local/python
which python3
/usr/bin/python3
EDIT:
More details about installation test.
After installation, I bring up the python console and try import PySide, as follows:
python
import PySide
ImportError: No module name PySide
But it works fine for python3:
python3
import PySide
PySide.version
'1.1.2'
You have two independent Python 2.7 installations, one in /usr and one in /usr/local. (And that's on top of the Python 3.x installation you also have.)
This is bound to cause confusion, especially for novices. And it has caused exactly the kind of consuion it was bound to cause.
You've installed PySide into the /usr installation, so it ended up in /usr/lib/python2.7/dist-packages. If you run /usr/bin/python, that import PySide will probably work fine. (If not, see below.)
But the default thing called python and python2.7 on your PATH is the /usr/local installation, hence which python says /usr/local/bin/python, so it can't see PySide at all. So you need to get it installed for the other Python as well.
Unless you know that you need a second Python 2.7 in /usr/local for some reason, the simplest thing to do would be to scrap it. Don't uninstall it and reinstall it; just uninstall it. You've already got a Python 2.7 in /usr, and you don't need two of them.
If you really need to get PySide working with the second 2.7…
Since you still haven't explained how you've been installing PySide despite being asked repeatedly, I can't tell you exactly how to do that. But generally, the key is to make sure to use explicit paths for all Python programs (python itself, python-config, pip, easy_install, etc.) that you have to run. For example, if the docs or blog or voices in your head tell you to run easy_install at some step, run /usr/local/bin/easy_install instead. If there is no such program, then you need to install that. The fact that you already have /usr/bin/easy_install doesn't help—in fact, it hurts.
If you can get rid of the second Python, but that doesn't fix PySide yet, uninstall, rebuild, and reinstall PySide. Or, even simpler… PySide has pre-made, working binary Ubuntu packages for all of the major Python versions that have Ubuntu packages. Just install it that way.
I've started to use python and recently i've bought my first mac.
I saw that Mountain Lion comes with their own python versions, despite i've decided to install a new python 2.7.5, and also Django and MySQL-Python. Everything works fine.
I've decided to try scipy and following the installed steps suggested by the official site with macports It seemed that macports installed another version 2.7.5 of python. Now if i try to run python in my terminal and import numpy it fails.
I saw that when i run python in my terminal, it execute
/Library/Frameworks/Python.framework/Versions/2.7/bin/python
But if I go in
cd /System/Library/Frameworks/Python.framework/Versions/2.7/bin
and run ./python i can import django and numpy modules but not MySQLdb modules.
I'm really confused how I can fix that mess.
I would like to have just one Python version installed in one place with all the modules I need.
Or please suggest something to clean that mess, know and have the control to what modules I have, where they are and how to import them! And also control which version of Python I want to run.
Edit 10/27/2013: i've solved following the link suggested in the comment, deleting all versions in /Library/ and all simlinks in /usr/local/bin, after that i changed to the path i wanted the py interpreter in my bash_profile.
Actually the problems seems to be created by macports that has installed numpy using the py interpreter installed under /System/, so i changed my default py interpreter to that installed under /System/ and installed the rest of packages i need. Now everything works as i want.
Personally, I wouldn't mess around with the built-in version of Python. I had some real issues with my Mac when I did that a few months ago.
You could try Canopy instead. It's a Python development environment which is great for writing and executing code. Any packages you need can be easily added (or removed) using the package manager. https://www.enthought.com/products/canopy/