SciPy in CMD works, but not IDLE - python

I am running Windows 7 Professional
I have installed Python 3.6
My version was verified by pip --version to give the following:
pip 9.0.1 from C:\ProgramData\Miniconda3\lib\site-packages (python 3.6)
Using PIP I have installed NumPy and SciPy by the following:
pip install numpy
pip install scipy
I can verify the instalation using pip list to show:
cffi (1.9.1)
conda (4.2.13)
cryptography (1
idna (2.2)
menuinst (1.4.4
numpy (1.12.1+m
pip (9.0.1)
pyasn1 (0.1.9)
pycosat (0.6.1)
pycparser (2.17
pyOpenSSL (16.2
pywin32 (220)
requests (2.12.
scipy (0.19.0)
setuptools (27.
six (1.10.0)
wheel (0.29.0)
In the command prompt I can type python, and then import scipy like so:
C:\Users\james.hayek\Desktop>python
Python 3.6.0 |Continuum Analytics, Inc.| (default, Dec 23 2016, 11:57:41) [MSC v
.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import scipy
>>>
It would appear as if everything has installed correctly. However, when I start IDLE and type import scipy I get the following error:
>>> import scipy
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import scipy
ModuleNotFoundError: No module named 'scipy'
>>>
Any idea's how I can call/import SciPy in IDLE?

Your Miniconda package has made its own Python SDK default. You need to run your IDLE and add Miniconda's site-packages directory to your regular PYTHONPATH:
import sys
print(sys.path) # to verify that Miniconda is not in this PYTHONPATH
sys.path.append('C:\ProgramData\Miniconda3\lib\site-packages')
To check your path you can equally go to File -> Path Browser

Related

venv cannot find python library even though I definitely have it installed

Im runnig a windows 10 machine, and im getting started on playing with virtual enviorments. I want to run a small fastapi application
I created a venv like this:
python -m venv venv
I then activated the venv, and installed my two dependencies:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> pip install fastapi
and
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> pip install unicorn
Which seemed to work fine, running pip list also seems to indicate that i have what I need:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> pip list
Package Version
----------------- ---------
beautifulsoup4 4.9.3
certifi 2020.6.20
cffi 1.14.3
chardet 3.0.4
crypto 1.4.1
cryptography 3.1.1
cycler 0.10.0
fastapi 0.63.0
idna 2.10
myModule 1.0.0
Naked 0.1.31
pip 21.0.1
pycparser 2.20
pycrypto 2.6.1
pydantic 1.8.1
PyYAML 5.3.1
requests 2.24.0
setuptools 49.2.1
shellescape 3.8.1
six 1.15.0
soupsieve 2.0.1
starlette 0.13.6
typing-extensions 3.7.4.3
unicorn 1.0.2
urllib3 1.25.10
wheel 0.35.1
But when I run my program it fails with the inmport of the fastapI:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> python .\main.py
Traceback (most recent call last):
File "C:\Users\Ask\python_Projects\garse_dockerAPI\app\main.py", line 3, in <module>
from fastapi import FastAPI
Also, running python my terminal doesnt wanna do it either:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> python
Python 3.9.0 (tags/v3.9.0:9cf6752, Oct 5 2020, 15:34:40) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import fastapi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'fastapi'
What's going on? why do i not have the dependencies i need?
EDIT:
In order to find the installation on my machine, I ran 'where python' in my normal terminal:
C:\Users\Ask>where python
C:\Users\Ask\AppData\Local\Programs\Python\Python39\python.exe
C:\Users\Ask\AppData\Local\Microsoft\WindowsApps\python.exe
Which give sme two different paths. I dont really know what to do with this information?
running where pip:
C:\Users\Ask>where pip
C:\Users\Ask\AppData\Local\Programs\Python\Python39\Scripts\pip.exe
When I run it in my venv, the commands output nothing at all:
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> where pip
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app> where python
(venv) PS C:\Users\Ask\python_Projects\garse_dockerAPI\app>
I definitely recommend using python3 -m pip instead of pure pip. It might save you some headache. The reason: when I used pip to install new packages in a venv virtual environment, they ended up in my OS environment! But just using python3 -m pip did the trick.
To make sure that the packages are called from your virtual environment, you can use python3 -m PACKAGE_NAME instead of PACKAGE_NAME. For example, flower didn't work in my virtual environment, but python3 -m flower works with no problem.
You can directly ask python where it is executed from! Try this:
>>> import sys
>>> print(sys.executable)
/PATH/TO/VENV/bin/python
>>> print(sys.version)
'3.10.5 (main, Jun 6 2022, 18:49:26) [GCC 12.1.0]'

Termcolor "colored" outputting weird characters

I have installed python into my command prompt(cmd) btw
command prompt:
C:\Users\*****> python -m pip install termcolor
Collecting termcolor
Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
Installing collected packages: termcolor
Running setup.py install for termcolor ... done
Successfully installed termcolor-1.1.0
You are using pip version 9.0.1, however version 19.3.1 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.
C:\Users\*****> python
#going into python now
Python 3.6.3 (v3.6.3:2c5fed8, Oct 3 2017, 17:26:49) [MSC v.1900 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from termcolor import colored
>>> print(colored("hi","green"))
right here is the weird output:
[32mhi[0m
I have tried python shell and it does not work.(see pic below)
if you are a Windows user, you need to do one extra step. Install the module named colorama. Then, at the top of your code include the code:
from colorama import init
init(autoreset = True)

No module named 'dbus.mainloop.pyqt5' even if all dependencies seem to be installed

I am trying to use DBUS as the main loop of PyQt5.
System-wide
I installed, system-wide (with apt, LinuxMint 19, amd64), the following dependencies:
python3-pyqt5 Version: 5.10.1+dfsg-1ubuntu2
python3-dbus Version: 1.2.6-1
python3-dbus.mainloop.pyqt5 Version: 5.10.1+dfsg-1ubuntu2
Trying it:
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from dbus.mainloop.pyqt5 import DBusQtMainLoop
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'
In a virtual env
I tried in a venv too. However, I had to accept system-wide packages, because I can't find a pip equivalent of python3-dbus.mainloop.pyqt5.
virtualenv --python=/usr/bin/python3 ~/.venvs/python3/testqtdbus5 --system-site-packages
source ~/.venvs/python3/testqtdbus5/bin/activate
$ pip install "pyqt5==5.10" dbus-python
Collecting pyqt5==5.10
Using cached https://files.pythonhosted.org/packages/ae/4b/c7315ba7a266d493ee50c4597b1b4dea2348896a49115b5192b21adf1a47/PyQt5-5.10-5.10.0-cp35.cp36.cp37-abi3-manylinux1_x86_64.whl
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages (1.2.8)
Collecting sip<4.20,>=4.19.4 (from pyqt5==5.10)
Using cached https://files.pythonhosted.org/packages/8a/ea/d317ce5696dda4df7c156cd60447cda22833b38106c98250eae1451f03ec/sip-4.19.8-cp36-cp36m-manylinux1_x86_64.whl
ERROR: pyqtwebengine 5.12.1 has requirement PyQt5>=5.12, but you'll have pyqt5 5.10 which is incompatible.
Installing collected packages: sip, pyqt5
Found existing installation: PyQt5 5.12
Not uninstalling pyqt5 at /usr/local/lib/python3.6/dist-packages, outside environment /home/vince/.venvs/python3/testqtdbus5
Can't uninstall 'PyQt5'. No files were found to uninstall.
Successfully installed pyqt5-5.10 sip-4.19.8
Trying:
$ ipython
/home/vince/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:925: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from dbus.mainloop.pyqt5 import DBusQtMainLoop
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ad501d00de5f> in <module>
----> 1 from dbus.mainloop.pyqt5 import DBusQtMainLoop
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'
Actually I want pyqt v5.12, for the WebEngine.
$ pip install "pyqt5==5.12.2" dbus-python
Collecting pyqt5==5.12.2
Downloading https://files.pythonhosted.org/packages/6a/f4/6a63aafcee3efd2b156dc835d9c85ca99b24e80f8af89b6da5c46054fe43/PyQt5-5.12.2-5.12.3-cp35.cp36.cp37.cp38-abi3-manylinux1_x86_64.whl (61.5MB)
|████████████████████████████████| 61.5MB 362kB/s
Requirement already satisfied: dbus-python in /usr/local/lib/python3.6/dist-packages (1.2.8)
Requirement already satisfied: PyQt5_sip<13,>=4.19.14 in /home/vince/.local/lib/python3.6/site-packages (from pyqt5==5.12.2) (4.19.15)
Installing collected packages: pyqt5
Found existing installation: PyQt5 5.10
Uninstalling PyQt5-5.10:
Successfully uninstalled PyQt5-5.10
Successfully installed pyqt5-5.12.2
$ ipython
/home/vince/.local/lib/python3.6/site-packages/IPython/core/interactiveshell.py:925: UserWarning: Attempting to work in a virtualenv. If you encounter problems, please install IPython inside the virtualenv.
warn("Attempting to work in a virtualenv. If you encounter problems, please "
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from dbus.mainloop.pyqt5 import DBusQtMainLoop
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-ad501d00de5f> in <module>
----> 1 from dbus.mainloop.pyqt5 import DBusQtMainLoop
ModuleNotFoundError: No module named 'dbus.mainloop.pyqt5'
Version of dbus.mainloop.init.py
In [2]: import dbus.mainloop
In [3]: help(dbus.mainloop)
# File location is: /usr/local/lib/python3.6/dist-packages/dbus/mainloop/__init__.py
So it seems the system version is used. Ok.
What am I missing ? Is there a pip package for the dbus mainloop ? Thanks.
edit: So far, I can work with the default
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
But if Gtk is now a dependency, that isn't satisfactory.
So far, I can work with the default glib mainloop:
EDIT: this won't work on other platforms than Linux (tested with MacOS).
from dbus.mainloop.glib import DBusGMainLoop
DBusGMainLoop(set_as_default=True)
glib is decoupled from Gtk, so it's alright I guess.

Import a still installed PyPi package in MinGW environment

I have problems doing import of packages I installed via pip3 in a MinGW environment. The module is not found but it is installed.
Buhtzy#Buhtzy MINGW64 ~
$ python3
Python 3.7.3 (default, May 28 2019, 08:37:07) [GCC 8.3.0 64 bit
(AMD64)] on win32 Type "help", "copyright", "credits" or "license" for
more information.
>>> import colorlog
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'colorlog'
>>> exit()
Buhtzy#Buhtzy MINGW64 ~
$ pip3 install colorlog
Requirement already satisfied: colorlog
in /usr/lib/python3.7/site-packages (4.0.2)
It is a MinGW 64bit on a Windows 10 machine.
Some background informations.
The pip3 binary
$ which pip3
/usr/bin/pip3
Which is a script with this content
$ cat /usr/bin/pip3
#!/usr/bin/python3.exe
# -*- coding: utf-8 -*-
import re
import sys
from pip._internal import main
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(main())
sys.path is
>>> print('\n'.join(sys.path))
C:/Users/Buhtzy/ownCloud/PROJEKTE/naoqi/lib
C:/msys64/mingw64/lib/python37.zip
C:/msys64/mingw64/lib/python3.7
C:/msys64/mingw64/bin
C:/msys64/mingw64/lib/python3.7/lib-dynload
C:/msys64/mingw64/lib/python3.7/site-packages
Python3 also is not able to install pip itself as a module.
$ python3 -m pip install colorlog
C:/msys64/mingw64/bin/python3.exe: No module named pip
I tried to install pip from PyPi
$ pip3 install -U pip
Requirement already up-to-date: pip in /usr/lib/python3.7/site-packages (19.1.1)
I do not understand MinGW but it looks like that Python3 is the default here.
So python is Version 3.7.3 by default.
All PyPi packages I installed with pip3 are able to load via python -m or directly inside the python interpreter shell.

Module import error in virtualenv but pip list --local shows it

I'm wondering about the following importError which I can't get ride off. I have a local virtualenv (venv) in which I've installed multiple modules:
(venv) stam#stam:~$ pip list --local
cryptography (1.5.2)
cvxopt (1.1.9)
cycler (0.10.0)
Cython (0.25.1)
matplotlib (1.5.3)
more-itertools (2.2)
ndg-httpsclient (0.4.2)
numpy (1.11.2)
pandas (0.19.0)
paramiko (1.15.2)
Pillow (2.8.1)
pip (8.1.2)
psycopg2 (2.6)
python-apt (0.9.3.12)
python-dateutil (2.5.3)
python-debian (0.1.27)
scipy (0.18.1)
setuptools (28.6.1)
simplejson (3.8.2)
urllib3 (1.9.1)
wheel (0.24.0)
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) stam#stam:~$
now starting a python interpreter and trying to import cvxopt (note it is in the list above) gives me a importError. Why is this? I'm using the right python version, I work on the venv so everything should work out of the box.
(venv) stam#stam:~$ python
Python 2.7.9 (default, Aug 13 2016, 16:41:35)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cvxopt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cvxopt
>>>
I'm a bit lost and don't know how exactly I can resolve this issue. It seems the right python version is started, at least the one I've attached to the virtualenv.
Additional outps asked for in the comments
(venv) stam#stam:~$ which python
/usr/bin/python
(venv) stam#stam:~$ which pip
/usr/local/bin/pip
Based on the output from which it seems clear that your python and pip belong to two different instances. So all libraries you install will be installed for some other python instance.
The acute fix is to force pip to run through your specified interpreter:
python -m pip list --local
python -m pip install cvxopt

Categories