As you can see below, The turtle package could not be install on the machine and raised errors and even note that i've install python-tk package on ubuntu, how could i solve the problem?
You don't need to install turtle at all
The turtle graphics library built on top of python-tk is part of the Python 3 standard library. It doesn't require installation: It's already included with Python 3.
The thing pip is trying to install is a much older library with the same name but built for a completely different purpose, which was never updated to be compatible with Python 3 in the first place.
Just import turtle. You don't need to install anything first.
(That said, note that you need python3-tk, not python-tk, to use turtle with Python 3).
To demonstrate the above, see https://packages.ubuntu.com/jammy/amd64/libpython3.10-stdlib/filelist, listing the files included in libpython3.10-stdlib for the Jammy release of Ubuntu; you'll see /usr/lib/python3.10/turtle.py included.
Related
Trying to install new packages via pip on Windows, but after it installs - Python cannot resolve the import. For Example, I have just installed the Python package similaritymeasures and pip correctly installed it, but when I import it into my Python program, it cannot find the import. Has anyone know a way around this?
Make sure that you restart VSCode after downloading your package. Sometimes, when you download a package while VSCode is still running, it doesn't recognize the package when using import similaritymeasures.
If that didn't work, then make sure that VSCode is using your preferred version of python. It is possible that you have more than one python version and it's using a non-compatible one to run your code. This can be done at the bottom right corner of the window by clicking the box that says: (for example) 3.9.5 64-bit. Then select a different (preferably older) version from the pop up widnow.
These are the solutions that came to my mind, I hope this helped.
I am installing python on windows10 and trying to install the opencv and numpy extentions in the command window. I get no error installing them and it says it is successfully installed. But when I try to check the installation and import cv2 it does not recognize it and give me the error: no module named cv2.
can anybody help me with this problem? Is there something wrong in installation process or do I need to install something else?
I checked the newest version of each and used the compatible one with my system.
Thanks.
One solution could be that you have 2 versions of python. So, go to the specific python's scripts directory and run: pip install numpy
If that too doesn't work, you can find the answers to this question on Why can't I import opencv3 even though the package is installed?, as stated by #Cut7er.
I have tried the solutions given to the above stated question myself also. But, they didn't work for me. So, another thing that you could try to use is this IDE called PyCharm. It ofcourse is much more beautiful that the IDLE, but it also has an inbuilt GUI controlled installation of binaries or packages. That would make things a lot easier. I have faced a lot of issues with packages for python and this IDE made things a lot easier. You can find it on https://www.jetbrains.com/pycharm/download/#section=windows.
You can also use anaconda. But, I found it a little difficult to use since, it has similar issues.
EDIT:
Seems like you are using PyCharm. But, you are installing libraries from your command prompt. So, see the answer to: ImportError: No module named 'bottle' - PyCharm. This answer guides you through how to install a certain library through your PyCharm window itself. So,
1) Go to Files>Settings
2) Search for "Interpreter" from the searching tab. Open the interpreter
3) You can now see a plus sign on the right. A click on it will open up a section on the left.
4) In the searching tab, search for numpy or opencv. Click on whichever module you want to install. And then click on the "install package" button on the bottom left. This will install the package for you.
5) Then click save. And run your file that says import cv/cv2.
This should probably do the trick.
Hope it helps!
Is it possible that you have 2 versions of python on your machine and your native pip is pointing to the other one? (e.g. you pip install opencv which installs opencv for python 2, but you are using python 3). If this is so, then use pip3 install opencv
I removed the Anaconda version on my machine, so I just have python 3.7 installed. I removed the python interpreter(Pycharm) and installed it again and the problem got fixed somehow!
I suspect you have two versions of python and the one you're using doesn't have opencv on it, because pip pointed to the wrong one.
A pragmatic solution assuming you're using the python version with conda is to just use conda to install cv2:
conda install -c menpo opencv
A more careful solution is to figure out how to get the pip that points to the python version you're using. On linux I can check that my pip points to my python like this:
:~$ which python
/home/kpierce/anaconda3/bin/python
:~$ which pip
/home/kpierce/anaconda3/bin/pip
So you see the pip and python versions are associated. On windows I suspect you do an analogous thing on the command line like
where python
where pip
And if they don't match, you might try
where python
where pip3
to see if those match. You need to use the pip that points to the correct python version. You can view the python version by entering the python interpreter and running
import sys
sys.version
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.
While I am installing pycairo using easy_install on osx, there is an error message as following:
Searching for pycairo
Reading http://pypi.python.org/simple/pycairo/
Reading http://cairographics.org/pycairo
Best match: pycairo 1.10.0
Downloading http://cairographics.org/releases/pycairo-1.10.0.tar.bz2
Processing pycairo-1.10.0.tar.bz2
error: Couldn't find a setup script in /tmp/easy_install-hnheQI/pycairo-1.10.0.tar.bz2
Please help me out. Thanks in advance.
It looks like pycairo is not set up to be easy_installable (or pipable).
The first problem is that the PyPI package pycairo points at the Python 3.x version, not the 2.x version (which is called py2cairo) This means you can't easy_install or pip install it for 2.x. And they don't have a separate py2cairo PyPI package. So, you'd have to explicitly easy_install http://cairographics.org/releases/py2cairo-1.10.0.tar.bz2.
The second problem is that the tarball isn't designed to be built with setuptools; you have to use waf.
So, you're going to have to download the link above (or, better, the latest py2cairo at http://cairographics.org/pycairo/), untar it, and read and follow the INSTALL directions.
This also assumes that you already have Cairo installed properly (e.g., via Homebrew).
PS, not that it would make any difference here, but you really should be using pip instead of easy_install. The only times you want to use easy_install are to install pip itself (sudo easy_install pip), and to install two or three packages that are easy_installable but not pipable.
You mentioned that you got Cairo through MacPorts. MacPorts doesn't play well with non-MacPorts. In fact, that's kind of the point: to have a completely isolated set of tools and libraries that can be maintained together. This means if you have MacPorts' cairo, you probably want its py27-cairo, and python27 package.
If you want something better integrated with your system, either look for binaries, use Homebrew, or build it yourself. (I noticed that Homebrew also has a formula for py2cairo, which I believe will install into your system 2.7 Python, but I haven't tested it. Normally, Homebrew doesn't supply Python/Ruby/Perl modules, because you've already got pip/gem/cpan, but they make exceptions for packages that don't work with the standard tools and/or are hard to set up.)
A colleague of mine wants to use my python 2 code on his OS X (10.6) machine. My code imports several built-in python packages, including Tkinter and shelve, and also uses third-party packages, including numpy, scipy, matplotlib, and ipython.
I've encountered a few problems with OS X's built-in python. (IDLE doesn't work, for example*). I suspect I should install a more recent version of python, and a different version of Tk.
My questions:
Will having two different versions of python/Tk on the same machine cause problems?
I would like to associate the terminal commands 'python', 'ipython', and 'easy_install' with the more recent version of python. How should I do this?
When I install third-party packages like numpy using a .dmg file, how do I control which version of python numpy installs into?
Is there a better way to do this?
If this process goes well, I'd consider adding OS X instructions to my code's documentation, so I'd like to boil down this process to the simplest, most general approach.
*EDIT: Also, this
EDIT: Thank you everyone for the useful answers. My colleague tried MacPorts, which seems to work well, but has a few speedbumps. First we had to install Xcode from the system install disk. This is not a fast or lightweight install (several GB). Luckily we still had the disk! Once Xcode was installed, MacPorts was easy to install. Python and the python subpackages we needed were also easy to install, but he told me this installation took several hours. Presumably this delay is due to compilation? He had an easy time setting the MacPorts python as default. However, I think we have to change the 'Python Launcher' application by hand, this seems to still default to the system python.
Even though he has a working system now, I'm tempted to ask him to try one of the other solutions. I'm not sure all of my code's potential users will tolerate a multi-hour, multi-gigabyte installation.
I use brew to install all my libraries/compilers/interpreters.
To install python try this:
brew install python
Then add Python's binaries directory to your $PATH in your ~/.profile:
export PATH=`brew --prefix python`/bin:$PATH
I'd recommend you to install pip, virtualenv and virtualenvwrapper to have better control over your environment too.
Have you tried ActivePython?
It includes a package manager (PyPM) that, by default, installs into your home directory (eg: ~/Library/Python/2.7). Main scripts get symlinked in /usr/local/bin; use the included pythonselect to set the active Python version.
You don't have to bother installing .dmg packages, as PyPM is a binary package manager ... therefore you can install non-pure Python packages like NumPy without having to compile things yourself.
ActivePython can use Apple's Tcl/Tk or, if installed, ActiveTcl.
A "simplest, most general approach" in your documentation could be:
Install ActivePython 2.7
Open Terminal and type pypm-2.7 install matplotlib ipython
Using MacPorts, you can install python 2.6, 2.7, 3.1 and 3.2 at the same time, with their own packages, without ever touching the built-in python.
numpy, scipy, matplotlib, and ipython are also available as ports for most of those python versions.
Moreover, if you install the python_select port, you'll be able:
to choose which one of those (plus the built-in python) is the "default" python;
to install python packages through easy_install/pip for the "selected" python, if they're not available as ports.
Add virtualenv to the mix, and you'll have a very, very flexible Python development environment.
As for your questions:
Q1: with MacPorts, no. while not a frequent user, I've installed and used matplotlib in 2.6 and 2.7, switching between the two using python_select.
Q2: easy_install, pip, ipython will be "linked" to the python they were installed by. (but see tip 1)
Q3: it's easier to install one of the py{26,27,xx}-numpy ports, or pip install numpy under your python_select'ed python.
Q4: well, MacPorts is the best thing I know after APT on Debian/Ubuntu... :-)
Now, two tips if you try MacPorts:
MacPorts cleanly installs ports separately from the OS X installation, in an /opt/local directory, and each python version is installed in a /opt/local/Library/Frameworks/Python.framework/Versions/{2.5,2.6,2.7,...} directory. Using python_select cleanly switch the "python" command using links. BUT... the Versions/{2.5,2.6,2.7,...}/bin directory, where python scripts are installed, is not added to the PATH. Just adding: export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/Current/bin:$PATH to your ~/.profile will always give you direct access to the scripts installed for the selected python.
to avoid bad surprises, I've added a echo Selected python is \"$(python_select -s)\" line to my ~/.profile, so I always know which is my currently selected python when opening a session... :-)
Regards,
Georges
In almost all cases, the best python to use is the one from http://python.org/. It sets up the paths correctly and doesn't overwrite anything. DMG package installs usually work automatically, as does python setup.py install, and it's not too hard to get setuptools to work. If you want per-user installs, it is easy to set up .pydistutils.cfg and python automatically recognizes the path install_lib = ~/Library/Python/$py_version_short/site-packages
An addendum regarding the usage of brew:
Since some time, brew install python will install python3.
If you intend to install python2, you want to use
brew install python#2
It is perfectly fine to install both python and python3 using brew!
Here is an old post that answers your questions too.
In general it is not a problem at all to have more than one python installation on your machine. You just have to watch out which one you are calling on the command line.
>> which python
... helps to identify where your python binary is located. The original Mac OS X python is usually at "/usr/bin/python"
I personally use the MacPorts python installation. It also supports you with the installation of modules. (see link above)
I have 4 versions of python on my MacBook Pro. 2 from the original install of OS X 10.6 and a subsequent update, then self installed copies of python 2.7 and 3.2. You can update the python command to point at any of the versions. They all install in separate directories and cause no problems with each other.
I'm not sure what will happen when you install from a .dmg file. I believe it will simply use whatever version python points to.
This post on superuser.com answers your questions on changing default paths.