I'm currently trying to run a file called forum.py in the vagrant directory but it returns an ImportError: No module named flask. After I logged out vagrant, when I type flask --version, the python version is 3.9.1 and the flaks version is 2.0.2. When I check the python version in vagrant, it returns 2.7.12. When I type flask-version, it returns flask: command not found. Does it mean the flask is installed to python 3.9 but not 2.7? Moreover, when I make a new directory in IDE for the files, should I choose Python3.9 or Python2.7 as my interpreter?
Ideally, together with your file, you have a requirements.txt for you to install the project dependencies on your machine, or better yet, on your virtual environment
Btw, if you are going to use your Global version of Python... Try to use the most current version.
Try the command: python3 forum.py
Related
if I run:
sudo gcloud components update
I get this warning:
WARNING: Python 3.4.x is no longer officially supported by the Google
Cloud SDK and may not function correctly. Please use Python version
2.7.x or 3.5 and up.
If you have a compatible Python interpreter installed, you can use it
by setting the CLOUDSDK_PYTHON environment variable to point to it.
My linux machine is Centos6 and my current python default versions are these:
myshell$ python --version
Python 2.6.6
myshell$ python3 --version
Python 3.4.10
I installed a Python 3.6 version, which is located here:
/opt/rh/rh-python36/root/usr/bin/python
myshell$ /opt/rh/rh-python36/root/usr/bin/python --version
Python 3.6.9
I hence added this line to the .bash_profile and sourced it:
export CLOUDSDK_PYTHON=/opt/rh/rh-python36/root/usr/bin/python
but I still get the same warning when running gcloud commands
Can anyone explain what am I doing wrong?
I think you can solve it do it the described here.
*Just go to the google-cloud-sdk folder and open the install.sh file.
*Change the CLOUDSDK_PYTHON="python" value to CLOUDSDK_PYTHON="python2.7"
*Rerun the install with the command
./install.sh
I am trying to package some python into an executable on MacOS (10.14.5). I am able to create the executable, but executing the resulting dist/hello_world executable gives the following error:
[55240] Error loading Python lib '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python': dlopen: dlopen(/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python, 10): no suitable image found. Did find:
/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python: code signature invalid for '/var/folders/yh/6_6mb2y96kg0gnb_nh9r2zrr0000gp/T/_MEIwUMw4X/Python'
My machine is running Python 3.7.7 installed from using the Mac installer downloaded from https://www.python.org/
For now, the script I am trying to package only contains print('hello world!') and the packaging command I am using is pyinstaller -F hello_world.py
I had success using pyenv and installing the specific version of python with the enable framework option:
env PYTHON_CONFIGURE_OPTS="--enable-framework" pyenv install 3.7.6
With this version of python (set using the command pyenv local 3.7.6 in the folder where hello_world.py is located), install pyinstaller (and any other modules you need) with pip. Then build with
pyinstaller hello_world.py --onefile --clean --windowed
which should give you a functioning dist/hello_word. As a python fledgling, I have no idea why this works as opposed to the steps in the original question. (I thought the Mac OS installer included the Python.framework by default -- I'm sure my ignorance is exposed here as this probably differs significantly from what the PYTHON_CONFIGURE_OPTS variable is doing above).
Also possible to do all this within a virtual environment (easily managed by pyenv-virtualenv).
The latest version of Pyinstaller only supports Python 2.7, 3.5–3.7. If you downgrade to Python 3.7 it will work!
I'm on Windows 10 and I am using PyCharm to run my application. I'm pretty new to Python and just coding in general.
I typed:
pip install flask
in the cmd prompt but forgot to open cmd prompt under administrator privileges. Could this be the problem? I ended up re-opening the cmd prompt with administrator rights and typed
pip install flask
again and it showed that it was already installed. I'm pretty sure I have flask installed on my system.
When I try to run the python file below which I named test_webapp.py I get the following error:
from flask import Flask
app = Flask(__name__)
#app.route("/")
def hello():
return "Hello World!"
if __name__ == "__main__":
app.run()
I get an error:
ModuleNotFoundError: No module named 'flask'
when i type in python --version into the command prompt i get version 3.6.3.
When i type the same code into the Python 3.6 (32-bit) command line, the code works! However, when i try to run it using the IDLE I get a SyntaxError and the number 6 in Python 3.6.3 gets highlighted in red.
Any ideas as to what's going on?
Try to install flask with specific version of python, do something like:
python[version] -m pip install flask
Note: replace [version] with python version (such as python3).
Sounds like the pip you are using is not installing for the same python you are using.
try which pip and which python
the they should be in the same folder. Might want to make an alias or two if you have a bunch of pythons (sys, 2, 3, conda etc) or just start with a fresh virtual env for your project. <- best imo.
When you typed pip install flask in the command prompt, it installed flask in the global environment. That is the reason when you run it in command line it works because it used global environment by default.
Pycharm has a virtual environment, therefore you need to install it in that virtual environment. Open Pycharm, then open the terminal within Pycharm and type "pip install flask".
You can read about virtual environment in python to get a clear idea.
Check version of python
python --version
And then use accordingly
if python 3.x.x then type
python3 app.py
if python 2.x.x then type
python2 app.py
I recently installed Ubuntu 16.04 and for ease of developing Machine Learning and other AI programs using Python2, I installed the Anaconda Python2 full distribution.
I always use 'guake' terminal emulator which I find best for productivity. So I installed Guake in my Ubuntu and when I try to run it, I get the following error:
/home/enlighter/anaconda2/bin/python2: No module named guake
I deleted all *.pyc files in /usr/lib/python2.7/dist-packages/guake/ folder, but that didn't help.
I am guessing this is an python environment issue. The /usr/bin/guake script contains only these rwo lines:
PYTHON="/usr/bin/env python2"
exec $PYTHON -m guake.main "$#"
Can anybody please tell me how to resolve this?
you don't execute the right Python execute: /home/enlighter/anaconda2/bin/python2 while you installed in /usr/lib/python2.7/dist-packages/guake/.
Use /usr/bin/python2 as default interpreter or install in /home/enlighter/anaconda2/lib/python2.7/dist-packages/guake/.
To install within anaconda python environment, clone the guake github repository and then build and install guake.
OK, I loaded Python 3.5 PYVISA, and set up my path variables in Windows, and import visa worked! Yay!
Now I want to create an executable, using cx_Freeze. I try running it, and it says it wants to see Python 3.4.
OK, I load Python 3.4. I add python34 paths to Windows and start up idle, load my script, and try to import visa, no module named visa.
What do I have to do to get the script to run under Python 3.4?
thank you
If you have installed pyvisa by using below command:
pip install pyvisa
Then it gets installed in site packages of python 3.5 (or) site packages of that specific python version (whichever python that is serving at that point of time)
If you want that to be available for all python versions, install it to separate folder and add that path as value to PYTHONPATH (system variable). If there is no such variable, create one. Command to install it to separate folder is:
pip install pyvisa -t c:\external
(Or)
Re-install it using pip from specific python version
C:\Python34\python.exe -m pip install pyvisa