I am attempting to use PySimpleGUI to create a very simple GUI, but when I run the command "python hello_world.py" I get the error:
File "hello_world.py", line 3, in <module>
import PySimpleGUI as sg
ImportError: No module named PySimpleGUI
I've run the command "pip install PySimpleGUI" and it says "Successfully installed PySimpleGUI-4.55.1." I'm not sure what I'm missing here.
Code snippet here:
# hello_world.py
import PySimpleGUI as sg
sg.Window(title="Hello World", layout=[[]], margins=(100,50)).read()
check where python is installed
import os
import sys
print(os.path.dirname(sys.executable))
>>C:\Program Files\Python310 #here 310 is python version your may be differrent
if this outputs inside C:\Program Files\Python310
check for C:\Program Files\Python310\Lib\site-packages\PySimpleGUI
if its not there then Run CMD as admin and try python -m pip install PySimpleGUI
Update pip to the current version via "python -m pip install --update pip".
It's strange, but my PySimpleGUI module became visible after I updated the pip from version 21.2.3 to version 22.0.4 via "python-m pip install --update pip".
Before the pip version update, the contents of my local environment looked like this:
(env) D:\work\PycharmProjects\demo>pip list
Package Version
----------- -------
flake8 4.0.1
mccabe 0.6.1
pip 21.2.3
pycodestyle 2.8.0
pyflakes 2.4.0
setuptools 57.4.0
WARNING: You are using pip version 21.2.3; however, version 22.0.4 is available.
You should consider upgrading via the 'D:\work\PycharmProjects\demo\env\Scripts\python.exe -m pip install --upgrade pip' command.
After the update:
(env) D:\work\PycharmProjects\demo>pip list
Package Version
----------- -------
flake8 4.0.1
mccabe 0.6.1
pip 22.0.4
pycodestyle 2.8.0
pyflakes 2.4.0
PySimpleGUI 4.57.0
setuptools 57.4.0
And the program hello_world.py it began to run successfully.
EDIT Dec2021:
This seems to me like an bug with pip rather than PySimpleGUI. Try this https://pip.pypa.io/en/stable/installation/ reinstall pip in the python interpreter using this.
Original Answer:
You can check all the installed packages with
python3 -m pip list
And see if you find PySimpleGUI in it. If yes then python3 hello_world.py should work if not (i suspect latter) run
python3 -m pip install PySimpleGUI
Maybe do this import:
import PySimpleGUI
and then the version of PySimpleGUI instead of:
import PySimpleGUI
Doing this:
C:/Users/Test> pip list
in the terminal, for me, it says there's PySimpleGUI installed.
Related
This is my first time trying to install a repo not in PyPI. I'm not sure if I'm having a general issue or a specific issue with the package.
Repo:
https://github.com/jeslago/epftoolbox
Instructions are:
git clone https://github.com/jeslago/epftoolbox.git
cd epftoolbox
Then, simply install the library using pip:
pip install .
I've tried several approaches.
I tried adding the repo in Pycharm, as "https://github.com/jeslago/epftoolbox.git/" in the settings.
I tried using pip install from a local version of the repo
python -m pip install C:\Users\user\epftoolbox\
I tried installing in anaconda
git clone https://github.com/jeslago/epftoolbox.git
cd epftoolbox
pip install .
I get this error
Successfully built epftoolbox termcolor
ERROR: tensorflow 2.3.0 has requirement scipy==1.4.1, but you'll have scipy 1.5.2 which is incompatible.
But it finishes with "Successfully installed epftoolbox-1.0"
The issue is that I can do "import epftoolbox"
Fine. But if I try and run a script with "from epftoolbox.data import read_data"
I get the error
ModuleNotFoundError: No module named 'epftoolbox.data'
So I take it that the package didn't actually install?
I'm not sure what to try next?
I've python 3.8.5 installed 64 bit.
I've get the same issue in pycharm and idle.
Probably you need to install specific version of scipy to work with this library, try to uninstall current version and then install the correct version with this commands:
python -m uninstall scipy
python -m install -Iv scipy==1.4.1
I am trying to build the python api for an open source project called Zulip and I keep running into the same issue as indicated by the screenshot below.
I am running python3 and my pip version is 10.0.0. The file in question is setup.py and the code that is messing up is when the pip.main() attribute is accessed to install a package.
Now, I know this build should succeed because its an open source project, but I have been trying for hours to fix the dependency issue regarding pip.main().
Any help would be greatly appreciated.
python3 -m pip install --user --upgrade pip==9.0.3
pip issue: rollback
It appears that pip did a refactor and moved main to internal. There is a comprehensive discussion about it here: https://github.com/pypa/pip/issues/5240
A workaround for me was to change
import pip
pip.main(...)
to
from pip._internal import main
main(...)
I recommend reading through the discussion, I'm not sure this is the best approach, but it worked for my purposes.
First run
import pip
pip.__version__
If the result is '10.0.0', then it means that you installed pip successfully
since pip 10.0.0 doesn't support pip.main() any more, you may find this helpful
https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program
Use something like
import subprocess
subprocess.check_call(["python", '-m', 'pip', 'install', 'pkg']) # install pkg
subprocess.check_call(["python", '-m', 'pip', 'install',"--upgrade", 'pkg']) # upgrade pkg
pip 10.0.1 still doesn't support main
You can choose to DOWNGRADE your pip version via following command:
python -m pip install --upgrade pip==9.0.3
This helps me, https://pip.pypa.io/en/stable/installing/
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
If you are using python3 and not set it default. do this,
python3 get-pip.py
It works for me.
My solution is to check the version number of pip and use the import the correct main function correctly
import pip
if int(pip.__version__.split('.')[0])>9:
from pip._internal import main
else:
from pip import main
def install(package):
main(['install', package])
To verify whether is your pip installation problem, try using easy_install to install an earlier version of pip:
easy_install pip==9.0.1
If this succeed, pip should be working now. Then you can go ahead to install any other version of pip you want with:
pip install pip==10....
Or you can just stay with version 9.0.1, as your project requires version >= 9.0.
Try building your project again.
If python -m pip install --upgrade pip==9.0.3 doesn't work, and you're using Windows,
Navigate to this directory and move the pip folders elsewhere.
Close your IDE if you have it open.
Press 'Repair' on Python 3.
Your IDE should cease to detect pip packages and prompt you to install them. Install and keep the last stable pip version by blocking automatic updates.
Pip 10.0.* doesn't support main.
You have to downgrade to pip 9.0.3.
Try this command.
python -m pip install --user pip==9.0.1
It works well:
py -m pip install --user --upgrade pip==9.0.3
Edit file:
C:\Users\kpate\hw6\python-zulip-api\zulip_bots\setup.py in line 108
to
rcode = pip.main(['install', '-r', req_path, '--quiet'])
do
rcode = getattr(pip, '_main', pip.main)(['install', '-r', req_path, '--quiet'])´
Not sure about Windows. But for mac users, use this:
pip install --upgrade pip==9.0.3
I fixed this problem upgrading to latest version
sudo pip install --upgrade pip
My version:
pip 18.1 from /Library/Python/2.7/site-packages/pip (python 2.7)
I faced the same error while using pip on anaconda3 4.4.0 (python 3.6) on windows.
I fixed the problem by the following command:
easy_install pip==18.* ### installing the latest version pip
Or if lower version pip required, mention the same in the command.
Or you can try installing the lower version and then upgrading the same to latest version as follow:
easy_install pip==9.0.1
easy_install --upgrade pip
For me this issue occured when I was running python while within my site-packages folder. If I ran it anywhere else, it was no longer an issue.
I have just reinstalled latest tensorflow on ubuntu:
$ sudo pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
[sudo] password for ubuntu:
The directory '/home/ubuntu/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/ubuntu/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting tensorflow==0.7.1 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl
Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.7.1-cp27-none-linux_x86_64.whl (13.8MB)
100% |████████████████████████████████| 13.8MB 32kB/s
Requirement already up-to-date: six>=1.10.0 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: protobuf==3.0.0b2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: wheel in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: numpy>=1.8.2 in /usr/local/lib/python2.7/dist-packages (from tensorflow==0.7.1)
Requirement already up-to-date: setuptools in /usr/local/lib/python2.7/dist-packages (from protobuf==3.0.0b2->tensorflow==0.7.1)
Installing collected packages: tensorflow
Found existing installation: tensorflow 0.7.1
Uninstalling tensorflow-0.7.1:
Successfully uninstalled tensorflow-0.7.1
Successfully installed tensorflow-0.7.1
When following the directions to test it fails with cannot import name pywrap_tensorflow:
$ ipython
/git/tensorflow/tensorflow/__init__.py in <module>()
21 from __future__ import print_function
22
---> 23 from tensorflow.python import *
/git/tensorflow/tensorflow/python/__init__.py in <module>()
43 _default_dlopen_flags = sys.getdlopenflags()
44 sys.setdlopenflags(_default_dlopen_flags | ctypes.RTLD_GLOBAL)
---> 45 from tensorflow.python import pywrap_tensorflow
46 sys.setdlopenflags(_default_dlopen_flags)
47
ImportError: cannot import name pywrap_tensorflow
Is there an additional change needed to my python or ubuntu/bash environment?
From the path in your stack trace (/git/tensorflow/tensorflow/…), it looks like your Python path may be loading the tensorflow libraries from the source directory, rather than the version that you have installed. As a result, it is unable to find the (compiled) pywrap_tensorflow library, which is installed in a different directory.
A common solution is to cd out of the /git/tensorflow directory before starting python or ipython.
The command below helped me.
pip install tensorflow --upgrade --force-reinstall
I compiled, installed TensorFlow from source (GitHub: https://github.com/tensorflow/tensorflow) in a Python 2.7 virtual environment (venv). It worked fine, but I needed (as others have mentioned, e.g. user "mrry" at Error running basic tensorflow example) to cd out of the partition in which I had compiled TensorFlow, to another partition, in order to be able to import tensorflow into Python. Otherwise, I got various errors, depending on which (source partition) directory I was in. To clarify:
source: /mnt/Vancouver/apps/tensorflow
can't import tf: Python launched in any of /mnt/...
can import tf: Python launched in /home/victoria/...
I later just followed the instructions here,
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md#anaconda-installation
and everything just works, fine.
For reference, I am operating on
Arch Linux [4.6.3-1-ARCH] x86_64
Intel i7-4790
xfce 4.12 desktop environment
INSTALL STEPS:
Modify paths, venv names as per your preferences.
Create tf-env:
cd /home/victoria/anaconda3/envs
conda create -n tf-env python=2.7 anaconda
Note: appending the 'anaconda' metapackage installs ALL Anaconda packages (NumPy; ...).
Source activate that venv (tf-env)
source activate tf-env
Note: added to ~/.bashrc as an alias:
alias tf='echo " [TensorFlow in Anaconda Python 2.7 venv (source activate tf]" && source activate tf-env'
Install TensorFlow in the tf-env venv:
(tf-env)$ conda install -c conda-forge tensorflow
THIS obviates the use of pip (including the *.whl install script), an alternative approach to installing TensorFlow that is described here:
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/get_started/os_setup.md).
WORKS!
(tf-env)[victoria#victoria ~]$ P
[P: python]
Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:42:40)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import tensorflow
>>> print tensorflow.__version__
0.9.0
>>> [Ctrl-D]
(tf-env)[victoria#victoria ~]$
You may then work with TensorFlow in the tf-env; e.g., in Jupyter notebooks launched in this (tf-env) venv.
Tensorflow 2.0 Compatible Answer: Both mrry's solution and neustart47's work for Tensorflow Version >= 2.0.
Answer 1: cd out of the /git/tensorflow directory before starting python or ipython.
Answer 2: pip install tensorflow --upgrade --force-reinstall or
!pip install tensorflow==2.0 --force-reinstall
In my python -m venv environment it appeared to be fixed by:
pip uninstall tensorflow
Change requirements.txt to say tensorflow==1.5.0 instead of tensorflow==1.8.0.
pip install -r requirements.txt
if you using CPU manufactured before 2011 then downgraded the tensorflow version from 1.8.0 to 1.5.0 or 1.2.0 and try to import the module it worked for me.
Installing via the following command solves the problem:
pip install --upgrade
Here's the link to download
I figured out that TensorFlow 1.12.0 only works with Python version 3.5.2. I had Python 3.7 but that didn't work. So, I had to downgrade Python and then I could install TensorFlow it works.
To downgrade your python version from 3.7 to 3.6
conda install python=3.6.8
I'm using tensorflow 1.13.1. Just reinstalling tensorflow worked for me.
I also have this issue and have been looking into it for a long time. It seems that there is no such problem on python 3+. On py2.7- The problem is actually on google.protobuf
Solution 1:
pip uninstall protobuf
pip uninstall google
pip install google
pip install protobuf
pip install google-cloud
Solution 2:
create an __init__.py in "google" folder.
cd /path/to/your/env/lib/python2.7/site-packages/google
touch __init__.py
Hopefully it will work.
I resolve the problem.
Try the follow command:
pip install --upgrade pip
I use windows 10 64-bit, python 3.6, pip 8.1.2 and kivy 1.9.1. kivywas installed according to the documentation.
After installing kivy I can't import it as I get this error
ImportError: No module named 'kivy'
How can I solve this I searched many times and followed the steps and it ends up with the same problem
Ensure you have the latest pip and wheel:
python -m pip install --upgrade pip wheel setuptools
Install the dependencies (skip gstreamer (~120MB) if not needed, see Kivy’s dependencies):
python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
python -m pip install kivy.deps.gstreamer
Note
If you encounter a MemoryError while installing, add after pip install an option
–no-cache-dir
.
For Python 3.5+, you can also use the angle backend instead of glew. This can be installed with:
python -m pip install kivy.deps.angle
Install kivy:
python -m pip install kivy
(Optionally) Install the kivy examples:
python -m pip install kivy_examples
The examples are installed in the share directory under the root directory where python is installed.
This is old, but if anyone stumbles on it the answer can be found here:
trying to install kivy on my pc i get the following errors
All the convenience of wheels can be found with 3.6 now as well as with older versions
I am trying to run Python unit test using mock on IDE: PyCharm.
Since I am using Mac (El Capiton), I am unable to do:
pip install mock
Therefore I did:
sudo -H pip install --ignore-installed six
sudo -H pip install --ignore-installed mock
It installed successfully. Now when I write a test, it throws following error:
File "/Library/Python/2.7/site-packages/mock/__init__.py", line 2, in <module>
import mock.mock as _mock
File "/Library/Python/2.7/site-packages/mock/mock.py", line 68, in <module>
from six import wraps
ImportError: cannot import name wraps
How can I resolve this?
Mock requires six version 1.7 or newer. pip show six to get the version and pip install --upgrade six to upgrade.
If that doesn't work, check which version of six is being loaded.
Check the Python Version
thomas:~$ python -c 'import six; print(six.__version__)'
1.10.0
Check the pip Version using pip show six
thomas:~$ pip show six | grep ^Version
Version: 1.10.0
Check the Python Location
thomas:~$ python -c 'import six; print(six.__file__)'
/Library/Python/2.7/site-packages/six.pyc
Delete the python version and pip version are different, delete six.py and six.pyc from the Python Location
Sources:
Stackoverflow
Github
Github
The issue is that there is an old version of six (1.4.1) in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python and in sys.path this directory comes before /Library/Python/2.7/site-packages where the newer version of six is installed. This looks to me like a configuration issue of the python Apple provides.
The easiest solution I could come up with is setting the PYTHONPATH environment variable explicitly to include /Library/Python/2.7/site-packages, so it ends up in sys.path before the /System/... path:
export PYTHONPATH="/Library/Python/2.7/site-packages:$PYTHONPATH"
I suppose installing a correctly configured python in /usr/local would do the trick as well.