Python Forum
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
unable to import pymysql
#4
(Jan-07-2019, 05:44 PM)nilamo Wrote:
(Jan-07-2019, 04:55 PM)IMuriel Wrote: hello, it was a Library problem, apparently the library did not install in C/python37/Lib/site-packages, it only was installed in my vev folder, so i just copied the libraries in the python37 path
That means you're not using the virtual environment. You created it, installed packages into it, but you aren't actually running your script from inside it.

https://docs.python.org/3/library/venv.html Wrote:Once a virtual environment has been created, it can be “activated” using a script in the virtual environment’s binary directory. The invocation of the script is platform-specific (<venv> must be replaced by the path of the directory containing the virtual environment):
Platform
Shell Command to activate virtual environment
  • Posix
    • bash/zsh $ source <venv>/bin/activate
    • fish $ . <venv>/bin/activate.fish
    • csh/tcsh $ source <venv>/bin/activate.csh
  • Windows
    • cmd.exe C:\> <venv>\Scripts\activate.bat
    • PowerShell PS C:\> <venv>\Scripts\Activate.ps1

actually i did that, but maybe i forgot to activate it before, to install the packages? im not sure, but is working so far, thanks for the reply

(Jan-08-2019, 12:27 PM)snippsat Wrote:
(Jan-07-2019, 04:55 PM)IMuriel Wrote: it only was installed in my vev folder, so i just copied the libraries in the python37 path
Don't do that in the future use pip to install to your OS Python,it's normal to use virtual environment when doing web-development. This create a isolated environment where all dependencies are in one place, will make it easier if need to move code to a server also a host to share code with the world eg DigitalOcean,Herko... ect. So with virtual environment you need to activate as pointet out bye @nilamo, or point your editor to the path of python interpreter in virtual environment(also python.exe). I quick demo of using venv.
# Make virtual environment C:\code λ python -m venv web_env # Cd in C:\code λ cd web_env # Activate,see (web_env) C:\code\web_env λ C:\code\web_env\Scripts\activate # Check pip (web_env) C:\code\web_env λ pip -V pip 10.0.1 from c:\code\web_env\lib\site-packages\pip (python 3.7) # Install PyMySQL (web_env) C:\code\web_env λ pip install PyMySQL Collecting PyMySQL Downloading https://files.pythonhosted.org/packages/ed/39/.../PyMySQL-0.9.3-py2.py3-none-any.whl (47kB) 100% |████████████████████████████████| 51kB 711kB/s Installing collected packages: PyMySQL Successfully installed PyMySQL-0.9.3 # Test that i work (web_env) C:\code\web_env λ python Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:05:16) [MSC v.1915 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import pymysql.cursors >>> exit() (web_env) C:\code\web_env λ
So at this point when Activate,it will always use dependencies inside virtual environment from command line. If in a editor need to point to C:\code\my_env\Scripts\python.exe, or there are editors that find virtual environment like eg VS Code,PyCharm.
hello, i think actually i did that, maybe i forgot to activate the venv when i installed the package?, but nvm now its working perfeclty so far, thanks for the reply anyway
Reply


Messages In This Thread
unable to import pymysql - by IMuriel - Jan-07-2019, 04:55 PM
RE: unable to import pymysql - by nilamo - Jan-07-2019, 05:44 PM
RE: unable to import pymysql - by IMuriel - Jan-08-2019, 08:56 PM
RE: unable to import pymysql - by snippsat - Jan-08-2019, 12:27 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating tables with pymysql using Xampp newbie1 0 2,143 Jul-15-2020, 11:10 AM
Last Post: newbie1
  pymysql.err.InterfaceError nikos 1 3,062 Feb-24-2019, 02:07 PM
Last Post: nikos
  Issue with bottle-pymysql nikos 13 5,566 Feb-23-2019, 11:15 AM
Last Post: nikos
  Insert data to SQL through pymysql and flask iainstott 3 7,755 Oct-24-2017, 03:04 PM
Last Post: iainstott

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020