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!
Related
I am new to Python and writing a lambda function.
I installed urllib3 using pip but still getting this following error.
I tried restarting vscode/ uninstall and reinstall but still getting the error.
this is the result when I run pip show urllib3
what am i missing here?
You need to make sure that VS Code uses the same Python Interpreter that you installed this package to.
You can see it here:
Looks like yours should point to
c:\user\###\appdata\local\programs\python\python39\bin\python
(or something like that, where your python executable file is located)
Maybe there is more than one python environment on your machine, And the location where you installed the package is inconsistent with the python interpreter you are using now.
You can use CTRL + SHIFT + P to open the command palette and search Python: Select Interpreter (or click on the interpreter version displayed in the lower right corner).
Select the environment interpreter where you have the urllib3 package installed.
I have downloaded Pandas library with pip install pandas through the command prompt, when I try to import pandas as pd PyCharm returns an error : ModuleNotFoundError: No module named 'pandas'
I have tried to uninstall and install again many times but nothing seems to work. Does anybody know a solution to this?
You can try downloading the library from PyCharm settings:
File -> Settings
then, Project: -> Python Interpreter
Click a + sign to the right,
Search for the pandas library,
and finally, press 'Install Package'
I think you have to choose the right python interpreter. Check my screenshot
You likely have multiple copies of Python installed on your system. PyCharm can be configured to use any version of Python on your system, including any virtual environments you've defined. The solution is to match up the version of Python you've installed Pandas into with the version of Python that PyCharm is using to run your code.
There are two places where you specify a Python version. First of all, your Project has a version associated with it. Check the "Python Interpreter" section of the "Project" section of your Preferences for that. That version is used for syntax highlighting, code completion, etc.
By default, the abovementioned Python version will also be used to run your code. But you can change the version of Python that your code is run with by creating or modifying a Run Configuration. To do this, check the menu next to the Run and Debug toolbar buttons near the top-left of your PyCharm window.
When you do get into the Python Interpreter section of the Preferences, you'll find that you can see all of the modules installed for each Python version that PyCharm knows about. You can use this to check to see if Pandas is installed for a particular Python version.
I would suggest you get comfortable with all that I've said above. It will save you many headaches in the future.
I am trying to install the huobi_python lib to my pycharm however i'm unable to do so. I have tried multiple times to add it and google it but did not succseed. Does anyone know how to fix this?
Github link:https://github.com/huobiapi/huobi_Python
Running windows 10, no i cannot find it in Project interpeter and with the + sign. Those are mostly REST api's
You wouldn't add it as an interpreter.
Since the project isn't available as pip install, you'd have to build it from source. Meaning clone the repo, and run the command listed in the installation section from the command prompt. Also make sure that you're using Python3.7, as listed there.
Your interpreter then would have to just be Python 3.7, which will allow you to import the modules from other Python code
from huobi import RequestClient
# your code
I've installed PyCharm with the robotframework support plugin.
The .robot files are identified successfully and I was able to create a simple script and run it in pyCharm.
However, my problem is that no keywords nor even the robotframework libraries (selenium2library) are recognized by pycharm in order to be autocompleted when typing them.
I also have the intellibot plugin installed.
Is there something that I'm missing? Is there another configuration file somewhere?
Thanks,
Try to set up your Library to robotframework-selenium2library == 1.8.0, then the issue will disappear.
If you have the last version it doesn't work for me.
My solution:
Uninstall the 'Robot framework support' (PyCharm/File/Settings/Plugins)
Uninstall 'Intellibot' (PyCharm/File/Settings/Plugins) (Uninstall all similar plugins!)
Exit PyCharm
Uninstall robotframework-seleniumlibrary (Open command prompt with administration mode: pip uninstall robotframework-seleniumlibrary)
Install robotframework-seleniumlibrary 3.3.1 (Command prompt: pip install robotframework-seleniumlibrary==3.3.1)
Open PyCharm
Install 'IntelliBot #SeleniumLibrary Patched' (PyCharm/File/Settings/Plugins)
(If it isn't working then try the following: PyCharm/File/Invalidate Caches/Restart... and click the 'Invalidate and Restart')
There is a bug in the intellibot plugin.
To resolve you need to
1. Uninstall your current intellibot plugin
2. Search for "IntelliBot #SeleniumLibrary Patched" in the plugins repository.
3. Install this patched plugin.
This worked for me.
You can try install "Robot Framework support" plugin.
it working for me.
use plugin Intellbot#SeleniumLibrary Patched
and robotframework-seleniumlibrary version 3.3.1
It works for me after lot of research from the internet
I recomend to use lte2000 fork: https://github.com/lte2000/intellibot
It works fine for me (Pycharm 2020.1, Robot Framework 3.2.2 and SeleniumLibrary 4.5.0)
In our main_resources.robot we need to give file path as below for the library files which contain definition of function
Library ../lib/SampleRest/SampleRest.py
When you do cntl+click on above SampleRest.py it should be navigated to that file
Your SampleRest.py should contain all your function definitions as below
try:
from .api import *
except:
from api import *
class SampleRest(
events,
repository,
devices
):
"""
This library will provides keywords to automating the cloud test cases
"""
ROBOT_LIBRARY_SCOPE = 'GLOBAL'
ROBOT_LIBRARY_VERSION = 1.0
def __init__(self):
for base in SampleRest.__bases__:
base.__init__(self)
Once I declare this I can use any of functions present in above devices.py file from robot file and it will be successfully navigated
Also please check your robotframework-seleniumlibrary version it should be 3.3.1 because for latest version navigation is an issue
I have been troubled by this for what seems to be forever.
Here are my configuration steps, and so far everything is working like a charm.
My setup:
Installed Python 3.9.x => added path to variables in "windows environment Variables" Check python and pip versions.
install selenium
install robotframework
install robotframework-seleniumlibrary
Install Pycharm and set Interpreter to Python 3.9.x
Install Plugin: "IntelliBot #SeleniumLibrary Patched" - Do not install Selenium2Library This is what causes the IDE issues.
Restart IDE and enjoy. And for those just getting into Robotframework, dont forget to add webdrivers.
For this I made a folder in root (called it webdrivers) and also added this to my Windows Enviro variables. This allows me to call them from any project folder.
I am going through the same problems... I've tried IntelliBot, IntelliBot #patched, Robot Framework Support plugins.
Now I am testing the Hyper RobotFramework Support plugin [link] and for now, looks the best from all of these.
With it I have some auto-complete support, also ctrl+click (navigation) works nice (better than in IntelliBot). Not perfect, but the best it has been so far.
I have installed:
PyCharm 2021.3.2
Python 3.10.2
Robot Framework 4.1.3
selenium 4.1.3
robotframework-seleniumlibrary 6.0.0
(on windows you can run the command pip list to see the version of the libraries that have been installed using pip)
When I write import MySQLdb in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get the error to go away, but what is the right way to handle this?
How can I help Eclipse know that MySQLdb is there?
It sounds like MySQLdb is somewhere on your sys.path, but not on your Eclipse project's PYTHONPATH; in other words, Eclipse thinks you're going to get an import error at runtime because you haven't fully configured it. Google seems to say that you can alter this setting in Window->Preferences->Preferences->PyDev->Python Interpreter to include the path to your MySQLdb module.
For some help figuring out where MySQLdb might be living on your system:
Open an interactive interpreter,
import MySQLdb
If that succeeds, you can get a hint from: print MySQLdb.__file__; it may be the __init__ file in the package that you need to point the path at.
cdleary above provided the reason two years ago, but this may be easier. Basically, one reinstalls the interpreter.
Select Window - > Preferences -> PyDev -> Interpreter - Python
Select the python interpreter in the upper pane
Click on Remove
Click on Auto Config
Agree to everything.
This works on Fedora 17 using the Eclipse 4.2.0 that came with the package management.
Fixed this by doing two things:
1) Added MySQLdb egg to the PYTHONPATH under Window->Preferences->Preferences->PyDev->Python Interpreter.
C:\Python26\Lib\site-packages\MySQL_python-1.2.3c1-py2.6-win32.egg
2) Close and re-open the .py file that had the red x.
Adding the egg works, but the error remains. The solution for that error can be found by adding
##UnresolvedImport
To the import statement, as in:
import web ##UnresolvedImport
Source: http://klaith.wordpress.com/2009/06/12/pydev-unresolved-import-errors/
I once had a similar problem on Windows (never encountered this on Linux though) and I discovered that I had to include the .egg directory of my library to my PYTHONPATH.
For example my PYTHONPATH (Pydev/Interpreter - Python/Libraries) included:
C:\Python26\Lib\site-packages
and I had to add:
C:\Python26\Lib\site-packages\jinja2-2.2.1-py2.6.egg
to use jinja.
This surely works I just tried it with Pmw package. Unzip package in site-packages. Then remove python interpreter from eclipse and then add it again. Your import errors shall go away. also you may want add module to forced builtins. See How do I fix PyDev "Undefined variable from import" errors? and http://pydev.org/manual_101_interpreter.html
I had a similar issue and the following is what I did to solve my issue. I have a Windows 8 Machine, Python 2.7 installed and running my stuff through eclipse.
Some Background:
When I did an easy install it tries to install MySQL-python 1.2.5 which failed with an error: Unable to find vcvarsall.bat. I did an easy_install of pip and tried the pip install which also failed with a similar error. They both reference vcvarsall.bat which is something to do with visual studio, since I don't have visual studio on my machine, it left me looking for a different solution, which I share below.
The Solution:
Reinstall python 2.7.8 from 2.7.8 from https://www.python.org/download this will add any missing registry settings, which is required by the next install.
Install 1.2.4 from http://pypi.python.org/pypi/MySQL-python/1.2.4
After I did both of those installs, I reopened eclipse and got a prompt to update the paths of eclipse which I accepted, after that I was able to query my MySQL db.
import MySQLdb
If this code show error like this:
Unresolved import: MySQLdb
you should add D:\Python27\Lib\site-packages\MySQLdb to your sys.path.
D:\Python27\Lib\site-packages\MySQLdb is this location where you install MySQLdb in your computer disk. After this step, the error will disappear.