I´m trying to install flask (PC, Windows, VS Code). Even when pip runs ok, and apparently the package is installed, I get the "module not found" message from Python.
This is what I have done so far:
First, uninstall for safety:
PS H:\Mi unidad\Projects\Webserver-raspi-V2> pip3 uninstall flask
Found existing installation: Flask 2.0.2
Uninstalling Flask-2.0.2:
Would remove:
c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages\flask-2.0.2.dist-info\*
c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages\flask\*
Then, reinstall:
PS H:\Mi unidad\Projects\Webserver-raspi-V2> pip3 install flask
Collecting flask
Using cached Flask-2.0.2-py3-none-any.whl (95 kB)
Requirement already satisfied: Werkzeug>=2.0 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from flask) (2.0.2)
Requirement already satisfied: click>=7.1.2 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from flask) (8.0.3)
Requirement already satisfied: itsdangerous>=2.0 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from flask) (2.0.1)
Requirement already satisfied: Jinja2>=3.0 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from flask) (3.0.3)
Requirement already satisfied: importlib-metadata in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from click>=7.1.2->flask) (4.6.4)
Requirement already satisfied: colorama in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from click>=7.1.2->flask) (0.4.4)
Requirement already satisfied: MarkupSafe>=2.0 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from Jinja2>=3.0->flask) (2.0.1)
Requirement already satisfied: zipp>=0.5 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from importlib-metadata->click>=7.1.2->flask) (3.5.0)
Requirement already satisfied: typing-extensions>=3.6.4 in c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages (from importlib-metadata->click>=7.1.2->flask) (3.10.0.0)
Installing collected packages: flask
Successfully installed flask-2.0.2
After that, check install status:
PS H:\Mi unidad\Projects\Webserver-raspi-V2> pip3 show flask
Name: Flask
Version: 2.0.2
Summary: A simple framework for building complex web applications.
Home-page: https://palletsprojects.com/p/flask
Author: Armin Ronacher
Author-email: armin.ronacher#active-4.com
License: BSD-3-Clause
Location: c:\users\gp\appdata\local\programs\python\python37-32\lib\site-packages
Requires: click, itsdangerous, Jinja2, Werkzeug
Required-by:
and, then, when trying to use it from Python (same error when running from VS Code):
PS H:\Mi unidad\Projects\Webserver-raspi-V2> python3 -c "import flask"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'flask'
Any ideas?
I guess that if you have installed the packages in the global environment, you should have no problem, but I had my python packages installed as a user.
You can solve this by adding my user's python dir to myapp.wsgi file.
As an example:
sys.path.append('/home/deployer/anaconda3/lib/python3.5/site-packages')
Related
I'm trying to install the discord-1.7.3 package. pip installs discord-1.7.3 and discord.py-2.0.1. My program is incompatible with version 2.x.x so I need only version 1.7.3 to install. The answers to this question suggest telling pip what version to install, but this doesn't work:
$ python3 --version
Python 3.9.2
$ pip install 'discord==1.7.3'
Collecting discord==1.7.3
Using cached discord-1.7.3-py3-none-any.whl (1.1 kB)
Collecting discord.py>=1.7.3
Using cached discord.py-2.0.1-py3-none-any.whl (1.1 MB)
Requirement already satisfied: aiohttp<4,>=3.7.4 in /home/username/.local/lib/python3.9/site-packages (from discord.py>=1.7.3->discord==1.7.3) (3.8.1)
Requirement already satisfied: multidict<7.0,>=4.5 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (6.0.2)
Requirement already satisfied: attrs>=17.3.0 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (22.1.0)
Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (4.0.2)
Requirement already satisfied: charset-normalizer<3.0,>=2.0 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (2.1.1)
Requirement already satisfied: aiosignal>=1.1.2 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (1.2.0)
Requirement already satisfied: yarl<2.0,>=1.0 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (1.8.1)
Requirement already satisfied: frozenlist>=1.1.1 in /home/username/.local/lib/python3.9/site-packages (from aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (1.3.1)
Requirement already satisfied: idna>=2.0 in /home/username/.local/lib/python3.9/site-packages (from yarl<2.0,>=1.0->aiohttp<4,>=3.7.4->discord.py>=1.7.3->discord==1.7.3) (3.3)
Installing collected packages: discord.py, discord
Successfully installed discord-1.7.3 discord.py-2.0.1
... you see discord.py-2.0.1 was installed anyway.
This answer suggests using pkg_resources to control what version is imported, but that doesn't work either:
$ cat test.py
import pkg_resources
pkg_resources.require("discord==1.7.3")
import discord
print(discord.version_info)
$ python3 test.py
VersionInfo(major=2, minor=0, micro=1, releaselevel='final', serial=0)
"How to only install (or import) a specific package version?" is the wrong question in this case.
You don't want to install the discord package at all, since it's just a mirror/placeholder.
This is a mirror package!
It is recommended to install discord.py instead.
If you want version 1.7.3 of Discord.py, then install the correct package:
pip install discord.py==1.7.3
In fact, the discord placeholder package doesn't even contain any code:
$ unzip -l discord-2.0.0-py3-none-any.whl
Archive: discord-2.0.0-py3-none-any.whl
Length Date Time Name
--------- ---------- ----- ----
381 08-20-2022 23:51 discord-2.0.0.dist-info/METADATA
92 08-20-2022 23:51 discord-2.0.0.dist-info/WHEEL
1 08-20-2022 23:51 discord-2.0.0.dist-info/top_level.txt
296 08-20-2022 23:51 discord-2.0.0.dist-info/RECORD
All it does is require discord.py>=2.0.0:
$ unzip -p discord-2.0.0-py3-none-any.whl discord-2.0.0.dist-info/METADATA
Metadata-Version: 2.1
Name: discord
Version: 2.0.0
Summary: A mirror package for discord.py. Please install that instead.
Home-page: https://github.com/Rapptz/discord.py
Author: Rapptz
License: UNKNOWN
Platform: UNKNOWN
Description-Content-Type: text/markdown
Requires-Dist: discord.py (>=2.0.0)
I need help understanding whats wrong here.
I will try to explain this as best I can, but Im a bit new to PythonAnywhere. I get this error:
Traceback (most recent call last):
File "/home/HelliottChip/mysite/app/__init__.py", line 6, in <module>
from flask_migrate import Migrate
ModuleNotFoundError: No module named 'flask_migrate'
When trying to run my main.py file. But i have them all installed as shown in this code:
17:14 ~/.local/bin $ pip install Flask-SQLAlchemy email_validator flask-mail pyjwt flask-bootstrap flask-moment
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2
.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Looking in links: /usr/share/pip-wheels
Requirement already satisfied: Flask-SQLAlchemy in /usr/local/lib/python2.7/dist-packages (2.4.1)
Requirement already satisfied: email_validator in /home/HelliottChip/.local/lib/python2.7/site-packages (1.1.2)
Requirement already satisfied: flask-mail in /usr/local/lib/python2.7/dist-packages (0.9.1)
Requirement already satisfied: pyjwt in /usr/local/lib/python2.7/dist-packages (1.7.1)
Requirement already satisfied: flask-bootstrap in /usr/local/lib/python2.7/dist-packages (3.3.7.1)
Requirement already satisfied: flask-moment in /home/HelliottChip/.local/lib/python2.7/site-packages (0.11.0)
Requirement already satisfied: Flask>=0.10 in /usr/local/lib/python2.7/dist-packages (from Flask-SQLAlchemy) (1.1.1)
Requirement already satisfied: SQLAlchemy>=0.8.0 in /usr/local/lib/python2.7/dist-packages (from Flask-SQLAlchemy) (1.3.10)
Requirement already satisfied: idna>=2.0.0 in /usr/local/lib/python2.7/dist-packages (from email_validator) (2.8)
Requirement already satisfied: dnspython>=1.15.0 in /home/HelliottChip/.local/lib/python2.7/site-packages (from email_validator) (1.16.0)
Requirement already satisfied: blinker in /usr/local/lib/python2.7/dist-packages (from flask-mail) (1.4)
Requirement already satisfied: dominate in /usr/local/lib/python2.7/dist-packages (from flask-bootstrap) (2.4.0)
Requirement already satisfied: visitor in /usr/local/lib/python2.7/dist-packages (from flask-bootstrap) (0.1.3)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (1.1.0)
Requirement already satisfied: Jinja2>=2.10.1 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (2.10.3)
Requirement already satisfied: click>=5.1 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (7.0)
Requirement already satisfied: Werkzeug>=0.15 in /usr/local/lib/python2.7/dist-packages (from Flask>=0.10->Flask-SQLAlchemy) (0.16.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python2.7/dist-packages (from Jinja2>=2.10.1->Flask>=0.10->Flask-SQLAlchemy) (0.23)
I have gone down about every website I can find on how to fix this, but I'm lost. This is for a Flask app I have worked on for a while on Replit.com and it worked fine until the transfer to PythonAnywhere. I have been trying to get this out for around two weeks now ^~^ but yet still no luck to my avail. I used a lot of this guide to help me with it, as I am also practicing my web deployment skills. (Don't need judgment on the fact I'm using flask -3-) But could anyone take thier time to help me with this? If you can, thanks a lot.
Check if your web app on PythonAnywhere is set up to be run by Python 2.7 -- I see you're using pip install outside of a virtual environment which by default will use pip for Python 2.7 as you can see in the output (btw. it won't work on PythonAnywhere, you need to provide --user option). If you want to install packages outside of virtual environment for different version of Python, use pipX.X install --user ... (where X.X should be replaced by required Python version). Also, remember to reload the web app every time the setup is changed. And if you're really stuck, maybe try contacting PythonAnywhere support (support#pythonanywhere.com) or use their forums?
Hello #TutorialWarrior9776 my suggestion is:
Step 1:
Install virtualenv,
pip install virtualenv
Step 2:
Create env
virtualenv -p python3.8 NAME_ENV
Step 3:
Activate env and Install requirements.txt (file generated local machine contains module flask_migrate)
source NAME_ENV/bin/active
pip install -r requirements.txt
Step 4:
Set your env path in the section (web) of pythonanywhere, that's all;
https://help.pythonanywhere.com/pages/Virtualenvs/
(Section: Step 3: Configure your app to use this virtualenv)
Hope this helps ;)
The error I am getting
Traceback (most recent call last):
File "C:\Users\Kieran\AppData\Local\Programs\Python\Python38-32\StockRank.py", line 1, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
I am using python 3.8
I tried:
pip3 uninstall requests
and reinstalling, but I get
Collecting requests
Using cached requests-2.24.0-py2.py3-none-any.whl (61 kB)
Requirement already satisfied: certifi>=2017.4.17 in c:\users\kieran\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests) (2020.6.20)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in c:\users\kieran\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests) (1.25.10)
Requirement already satisfied: chardet<4,>=3.0.2 in c:\users\kieran\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in c:\users\kieran\appdata\local\packages\pythonsoftwarefoundation.python.3.8_qbz5n2kfra8p0\localcache\local-packages\python38\site-packages (from requests) (2.10)
Installing collected packages: requests
Successfully installed requests-2.24.0
Once I try to run the program I get the same error message. I believe I am using the updated version of pip as well. Maybe It could be an issue with the paths, but I am not sure how to check that
I am running Catalina MacOS with python 3.7.5. I am trying to run an ansible script to install a VM. This Requires python >= 2.6 and PyVmomi. I have installed PyVomi and pyVim via pip. Both were installed successfully. When I run the playbook, I get the error message below. Not sure what I am missing.
TASK [Create a virtual machine on given ESXi hostname] *************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: ImportError: No module named pyVim
fatal: [localhost -> localhost]: FAILED! => {"changed": false, "msg": "Failed to import the required Python library (PyVmomi) on MacBook-Pro.local's Python /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python. Please read module documentation and install in the appropriate location"}
ArunJose_Intel is correct. The module is pyvmomi, not pyVim. Although the error indicates that the pyVim library was missing. It was misleading as I could see it in my directory. Following his advice I changed the pip install command to install pyvmomi instead.
pip install pyvmomi
I was able to run the python script with pyVim imported. Thank you Arun.
You might have installed PyVomi and pyVim for the wrong python executable. You have to make sure you are installing via pip to the right python. You are installing the packages to the python3.x present in your machine. What you have to do is to install the pip packages to the python of the playbook
I fixed it.
pip3 install ansible
That made ansible use python3
Sorry for the confusion. I have installed this via pip3, is yes they are installed in the python3 directories.
pip3 install PyVmomi
Requirement already satisfied: PyVmomi in /usr/local/lib/python3.7/site-packages (6.7.3)
Requirement already satisfied: requests>=2.3.0 in /usr/local/lib/python3.7/site-packages (from PyVmomi) (2.22.0)
Requirement already satisfied: six>=1.7.3 in /usr/local/lib/python3.7/site-packages (from PyVmomi) (1.13.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/site-packages (from requests>=2.3.0->PyVmomi) (2019.9.11)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/lib/python3.7/site-packages (from requests>=2.3.0->PyVmomi) (1.25.7)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.7/site-packages (from requests>=2.3.0->PyVmomi) (3.0.4)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.7/site-packages (from requests>=2.3.0->PyVmomi) (2.8)
pip3 install pyVim
Requirement already satisfied: pyVim in /usr/local/lib/python3.7/site-packages (3.0.2)
Requirement already satisfied: docopt in /usr/local/lib/python3.7/site-packages (from pyVim) (0.6.2)
Requirement already satisfied: prompt-toolkit<3.1.0,>=2.0.0 in /usr/local/lib/python3.7/site-packages (from pyVim) (3.0.2)
Requirement already satisfied: pyflakes in /usr/local/lib/python3.7/site-packages (from pyVim) (2.1.1)
Requirement already satisfied: pygments in /usr/local/lib/python3.7/site-packages (from pyVim) (2.5.2)
Requirement already satisfied: six in /usr/local/lib/python3.7/site-packages (from pyVim) (1.13.0)
Requirement already satisfied: wcwidth in /usr/local/lib/python3.7/site-packages (from prompt-toolkit<3.1.0,>=2.0.0->pyVim) (0.1.7)
I tested a python script to send anythink with Pushover. But I get the error "ImportError: No module named pushover"
My installed Versions:
# pip install python-pushover
Collecting python-pushover
Using cached https://files.pythonhosted.org/packages/6f/3d/144a0137c749bd152c3ab7f4d3ce8fe1455168dab36c2fcd900d3fab16ad/python-pushover-0.4.tar.gz
Requirement already satisfied: requests>=1.0 in /usr/local/lib/python3.5/dist-packages (from python-pushover) (2.21.0)
Requirement already satisfied: urllib3<1.25,>=1.21.1 in /usr/local/lib/python3.5/dist-packages (from requests>=1.0->python-pushover) (1.24.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.5/dist-packages (from requests>=1.0->python-pushover) (3.0.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.5/dist-packages (from requests>=1.0->python-pushover) (2018.11.29)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/lib/python3.5/dist-packages (from requests>=1.0->python-pushover) (2.8)
Installing collected packages: python-pushover
Running setup.py install for python-pushover ... done
Successfully installed python-pushover-0.4
# python -V
Python 2.7.13
# python3 -V
Python 3.5.3
The scriptheader:
#!/usr/bin/env python
import pushover
I have tried with pip(3) to install python-pushover but with no success.
I faced this exact error today. This is due to co-existing of different versions of python in your system.
Do, /usr/bin/python3 if the module was installed for py3 and just /usr/bin/python for py2 before running the script.
Refer Installed module using pip, not found for more.
In my case, you should :
uninstall that package:
pip uninstall pushover
and install the correct package:
pip install python-pushover
And your code will work fine.