Unresolved reference flask_sqlalchemy - python

I am using Pycharm, with python 3.8 and I am watching a flask tutorial for beginners. this means that I am a beginner so I might not understand every vocab or solution, however, a little research on my end will make it alright.
So the problem I am having is that I downloaded flask_sqlalchemy with the following code on the PyCharm terminal:
pip install Flask-SQLAlchemy
I thought I had been successful since the event log also said installation successful. However, when I wrote the following code:
from flask_sqlalchemy import SQLAlchemy
it reported "unresolved reference flask_sqlalchemy"
I then tried entering this in the terminal thinking it would work:
pip install -U Flask-SQLAlchemy
Nothing changed.
I tried installing SQLAlchemy to see if it would do something but it didn't.
I used the following code in the terminal:
pip install SQLAlchemy
Any ideas on how to get this to work?

Go to File -> Preferences -> Python Interpreter. Hit the plus button and install the package SQLAlchemy.
If that does not work, go to File -> Invalidate Cache.
What finally worked for me was deleting the venv folder, deleting the interpreter, and creating a new one. Make sure to enable inheritance of global packages because when you use pip3 install Flask-SQLAlchemy it installs to the default interpreter.
You really should be able to install it to your virtual environment. But I spent 3hrs on it and couldn't figure out how.
If you're still stuck, refer to "Python shows unresolved references error for valid code.

Related

Python program runs through sublime but not command line

I am attempting to make a web app with flask, and when I attempt to run my script through the command line, I get a "ModuleNotFoundError: No module named 'google.cloud'". However, when I run the script in Sublime, I do not get this error.
I have already attempted installing google, google-cloud, and conda using pip.
Here are the lines that are involved in importing from google.cloud. The console states that the first line is the one the compilation is failing at.
from google.cloud import vision
from google.cloud.vision import types
I was expecting the code to be output to my localhost, but this compile time error is preventing this.
The library|package that you need is called google-cloud-vision, see:
https://pypi.org/project/google-cloud-vision/
You could add this directly to your project (at its current version) using:
pip install "google-cloud-vision==0.36.0"
However...
Your problem may be a consequence of different python environments and I encourage you to review virtualenv:
https://virtualenv.pypa.io/en/latest/
Among other things, virtualenv enables (a) the creation of isolated python environments; (b) "clean room" like behavior wherein you can recreate python environments easily and predictably. This latter benefit may help with your "it works .... but doesn't work ... " issue.
One additional good practice, with|without virtualenv is to persist pip install ... to (conventionally) requirements.txt:
pip install -r requirements.txt
And, in this case, to have requirements.txt similar to:
flask==1.0.2
google-cloud-vision==0.36.0

Error in template flask run AndreiD/Flask-Easy-Template

Good Morning!
I am a beginner in the python / flask world ... I found this template and found it complete and simple, good for beginners and with some interesting features.
I just can not run this template. It has some packages that do not install by pip (pycrypto==2.6.1, python-cloudfiles==1.7.11, python-loaders==0.2.3).
Was this a reason? Can anybody help me?
I need some help to run this template.
enter image description here
Thanks!
This project is unmaintained, please try this one instead.
For your question, flask.ext.foo is the old way to import extension and it is removed in Flask 1.0. If you want to fix it, try the methods below:
Method 1: Fix old import statements
Find these lines in application/__init__.py:
from flask.ext.cache import Cache
from flask.ext.sqlalchemy import SQLAlchemy
change them to:
from flask.cache import Cache
from flask.sqlalchemy import SQLAlchemy
Method 2: Use a virtual enviroment
Everything will be ok if you use the pinned version in the project's requirement file. Just create a virtual enviroment with virtualenv, pipenv, poetry, venv etc, activate the virtual enviroment, then install dependency from the requirements.txt file.

mysql-connector won't import into script in pycharm

I have successfully installed mysql-connector using pip.
Installing collected packages: mysql-connector
Running setup.py install for mysql-connector ... done
Successfully installed mysql-connector-2.1.6
However, in PyCharm when I have a script that uses the line:
import mysql-connector
PyCharm gives me an error saying there isn't a package called "mysql" installed. Is there some sort of syntax that should be used to indicate that the entire package name contains the "-" and is not just "mysql"?
When I run my script in IDLE, mysql.connector imports just fine. (I changed it to mysql-connector after seeing the "-" in the name of the package and having trouble in PyCharm.)
EDIT: per #FlyingTeller's suggestions, in the terminal, "where python" returns C:...Programs\Python\Python36-32\python.exe. "where pip" returns ...Python\Python36-32\Scripts\pip.exe. The interpreter in PyCharm for this project is this same filepath & exe as "where python" in the terminal.
Per #Tushar's comment, this program isn't using a virtual environment and the mysql-connector library is already present in the Preferences->Project->Python Interpreter.
Thanks for the feedback and any additional guidance you may be able to provide.
You need to import the connector as
import mysql.connector
Check the examples in the docs for this
If that doesn't work, then there might be an inconsistency between the interpreter that pycharm uses and the one you installed the package for. In pycharm, go to
File->Settings->Project Interpreter
In the terminal, enter
where python #Windows
which python #Linux
and also
where/which pip
make sure that the interpreter configured in pycharm is the same that appears when typing which/where python in the command line/shell. Also make sure that pip also points to the same python distribution.
It may be because you are using a virtual environment inside pyCharm, while you might have installed the library using system's default pip.
Check Preferences->Project->Python Interpreter inside Pycharm, and see if your library is listed there. If not, install it using + icon. Normally, if you use pyCharm's inbuilt terminal, it is already using the same virtual env as your project. So using pip there may help.
Usage syntax is as below:
import mysql.connector
conn = mysql.connector.connect(
user='root',
password='#####',
host='127.0.0.1',
database='some_db')
conn.close()
Go to project interpreter and download mysql-connector.You need to install it also in pycharm
I was having this exact issue as well, after a while i solved it by simply changing the name of my script in PyCharm, turns out i had named my script mysql.py (because it was my first time attempting to connect it to python) and it was critically interfering with the import.
TLDR: Change the name file if it's asssigned as mysql.py, as it takes priority over the mysql-connector and prevents it from being imported, even if installed correctly.
People have commented with reasonable responses (and I'm sure OP is good on this by now) but they weren't super clear to me...
Don't use "pip3 install" in terminal in your pycharm project. In fact, uninstall any mysql connectors you have already using this method.
So now that you have verified there are no other mysql connector packages... Add the package "mysql-connector-python" using the Python Interpreter only (in preferences) in your pycharm project. Now the package should work!

Python: Custom package installation not importing module

I'm having a problem with this package that I installed in Python 3.5. After installing it, I try to run requestProxy.py but it won't import any of its own packages. Here's what I did, and what's happening.
I cloned it and created a private repo using these instructions.
I installed in an activated virtualenv, created without using sudo, using:
pip3 install -e HTTP_Proxy_Randomizer
Terminal said it installed ok.
I can find the egg link in my virtualenv's site-packages folder, but when I try to run the main file, it says:
from project.http.requests.parsers.freeproxyParser import freeproxyParser
ImportError: No module named project.http.requests.parsers.freeproxyParser
I had to write a setup.py for the package, which didn't seem to come with its own. I came up with:
setup(name='HTTP_Request_Randomizer',
version='1.0',
description='HTTP Proxy Request Randomizer',
package_dir={'project': 'project','http':'project/http',\
'requests':'project/http/requests','errors':'project/http/requests/errors',\
'parsers':'project/http/requests/parsers','proxy':'project/http/requests/proxy'},
packages=['project','http','requests','errors','parsers','proxy']
Here's the package structure:
pip3 freeze
gives me:
Complete output from command git config --get-regexp remote\..*\.url:
fatal: bad config file line 4 in /home/danny/.gitconfig
----------------------------------------
Error when trying to get requirement for VCS system Command "git config --get-regexp remote\..*\.url" failed with error code 128 in /home/danny/Documents/HTTP_Request_Randomizer, falling back to uneditable format
Could not determine repository location of /home/danny/Documents/HTTP_Request_Randomizer
Django==1.9.7
## !! Could not determine repository location
HTTP-Request-Randomizer==1.0
mysqlclient==1.3.7
So I want to have requestProxy.py install the other necessary packages and not fail at line 1. I'm sure this is a problem with my implementation and not the original author's coding. I was experimenting with this package a couple of weeks ago before I was aware of virtualenvs or pip install -e, and just copied it manually to site-packages. It worked then. Now I understand the concepts to do it more cleanly, but I can't get those to work.
It feels as though I have done something wrong with my git config or with my package_dir structure in setup.py, perhaps?
I've been pythoning for maybe a month and have a lot to learn. I normally find what I need on Stack Overflow without having to bother anyone, but after trying everything with this, I really need some help. Any advice much appreciated.
I figured it out. I was using Ninja IDE, and even though I entered the virtualenv for the project and restarted, it still wasn't recognizing it. I was able to run it from the terminal, and also in Pycharm and Liclipse.

Failure to install ndg-httpsclient or maybe I'm doing the solution wrong

I'm new to python and have a little experience with VS, C# and WPF.
My question might seem similar to some asked questions, but I tried several of the suggested solutions (that worked for others), and yet it doesn't work for me.
I'm trying to build a simple WPF application that will send http requests.
The solution structure is as follows:
Solution MyApp
Project 1 <This is the startup project>
GUImodul.py
queryStringBuilder.py
<This project uses IronPython env for the WPF support>
Project 2
QuerySender.py (includes two classes)
<This project uses Python 3.4 env, only in this one I managed installing the "requests" package which I need for sending the query>
When I try to run this I get an error "No module named ndg.httpsclient.ssl_peer_verification", even though I only import from project 2 a class that doesn't contain any import from "requests" (it only creates an instance of the other class there that does have such import).
When I try to install ndg-httpsclient using pip, I get "Command python setup.py egg_info failed with error code 1".
Things I tried so far:
Adding "-X:FullFrames" to the debug properties of both projects
(re)installing steuptools with from ez_setup.zip
As said - ndg-httpsclient is installed for Python34
Using the "import requests" command only within the class NOT imported to Project1 (the one with IronPython env)
Tried installing a newer(?) version of urllib3
So...
I just might be doing something fundamentally wrong in this solution, which in this case I wish someone to help me understand what it is.
Otherwise, any idea what can I try next to make this thing work?
If you read the fine print, ndg-httpsclient is incompatible with Python 3, as it was developed for Python2.7 . That's probabably the root cause.
RE: Why is Python 3.0 not backward compatible?

Categories

Resources