I'm trying to copy some text to clipboad in my python program, so I've installed pyperclip via pip command via Windows command line interface, it says everything is successfully installed, not a problem. However, when I import the thing into my project, I get
from tkinter import *
from tkinter import ttk
import pyperclip
import binascii
#my code...
...
ModuleNotFoundError: No module named 'pyperclip'
So I was like *** that, maybe it's broken, I found a little library that does exactly the same, called "clipboard". Exactly the same installation procedure - from the command line. Same successful installation. Same ModuleNotFoundError. So clearly something wrong on my side, but I have no idea what it is, no idea where to look and what to do. I just want to be able to copy some text to clipboard. Multiplatform. That's it.
It's Python 3.8, Windows 10
pyperclip-1.8.0
pip-20.2.2
If I need to show you some logs or tell you something about my installation, please tell me what exactly to do and where to find information you may need. I'm good with instructions, but I don't have much (any) experience rummaging through logs and python installation folders.
Similar posts have slightly different problems, I didn't find any clear solution or hints that I could understand. No reply seemed like a solution to me.
Anyway, I would really appreciate any help from the community. Being unable to simply copy something to clipboard is killing me, especially since it's the only thing I can't implement. And it's just one function for one button to copy one short piece of text. It's like being stuck at 99% loading, when everything is done, and you just can't write the final line of code, haha.
Pycharm uses a virtualenv for pycharm projects. Navigate through:
Pycharm >> File >> Settings(or press Ctrl+Alt+S on win) >> Project:Name >> Project Interpreter >> Click on the plus(+) symbol above the scroll bar and type in pyperclip and press install package.
And this will install pyperclip for your Pycharm IDE. Since pycharm uses a virtual env for its projects you can change it in the project interpreter section as well, and then the pyperclip you installed from the cmd using pip, will be available to be used on that global version of python(now used by your Pycharm too).
If you still have any errors or doubts, do let me know :D
Cheers
Related
Everything in my code was working perfectly fine up until I decided I wanted to utilize match-case in Python. Find out its only a thing in 3.10+, so I quickly install it and change it to be the interpreter in command palette.
Then I try to run my code same as before, and I'm not sure what changed but my Keyboard import is giving me 'Import "keyboard" could not be resolved'. Issues. The same issue was actually present as well with the 'from nis import match' module.
I installed keyboard initially using 'pip install keyboard' when running my 3.9 version, and legit everything was fine. This all started after I installed 3.10 (which I did from Pythons website yes); and I did add to PATH, but I dont think that would have any impact on my imports in VScode.
Confused as heck right now, please look at my screenshots for clearest explanation of what I'm facing.
Import could not be resolved
.
Module Not Found Error
.
pip3.10 show keyboard
.
My interpreter list from command palette
Any and all help appreciated, I'm extremely confused and think I've tried it all now
New Python versions use new site-packages folders. You need to reinstall everything. This is why poetry, pipenv, or requirements.txt are used
I think the linter-like extension/whatever Pylance is is the problem. Why? Because as we've tried, pip install keyboard and pip install --upgrade keyboard just confirm that the requirement is satisfied and the latest version of keyboard is already installed.
What I did was change Pylance's settings. Yes, it's not an actual error (with the code), but Pylance's problem. It just didn't see enough files in the keyboard package to satisfy its hunger, or Microsoft was just too lazy to pass more checks and update it accordingly, because however it happened, when I tried changing the setting to display an "error" at "missing imports" for fun, it didn't show errors or the default "warning" but "none", because I had run the file before I changed it back to display an error (maybe Pylance observed that when the file was run, there was no ModuleNotFoundError, and so stopped showing the warning).
I better shut now, because the setting I changed/overrode by adding it in settings.json is:
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
which is in:
{
...,
...,
...,
"python.analysis.diagnosticSeverityOverrides": {"reportMissingImports":"none"}
}
Here is a list of keys like "reportMissingImports" whose values you can change. These are the allowed values for the keys in python.analysis.diagnosticSeverityOverrides:
error (red squiggle)
warning (yellow squiggle)
information (blue squiggle)
none (disables the rule)
You would want to change their values only if you want to change their behaviour.
You can find settings.json by its path or by going to the settings GUI and clicking on any "Edit in settings.json" link-like button. You can also make settings.json open instead of the GUI by default.
Now, you won't see any more warnings when you import modules and can code without being anxious about the stupid warning.
Wow, So as it turns out, a solution I tried previously, to no avail is now working to solve this bizarre issue.
Simply put, I once again went to Command Palette (Ctrl+Shft+P), and looked through my interpreters I had to see what could be wrong.
Decided to click on the 'recommended' option I assumed I had been running this whole time. Turns out I was using this 'third' option as shown in the screenshot (the one not highlighted ofcourse); and it's the reason my module installs were being found on my machine, but not by the interpreter; as such giving me errors and not running the module for the program.
Simple error, but thanks to those who did help.
I'm trying to work on some old code that used a library I'm not very familiar with anymore, and am getting the 'No module named' error. I'm using sublime text editor on windows. I had edited some things in build to run c++ previously if that might effect it.
If the library in particular matters, it is youtube_dl
I have tried $pip install -upgrade youtube_dl but it hasn't changed anything.
The code that is throwing an error is import youtube_dl
I searched around on the internet, and I found an answer.
(Edited for clarity)
”Sublime is a module only available in Sublime Text embedded Python interpreters.
import sublime will only work from a plugin or inside the console, not on your system Python interpreter.”
The forum post is here.
Not sure if this will help, as I do not know if you are trying to import sublime, but this is literally all the info I could find.
Hopefully this helps!
Just working my way through a (very good) book call Test Driven Development using Python.
This makes use of Python3.4 by the way. By the way, I am running in a Windows 7 OS.
I've got all the stuff working using a simple text editor and running from the command line... in the course of which in particular I used "pip install" to install Django and Selenium, as per book's instructions.
This created folders "selenium" and "django" under ...\Python34\Lib\site-packages\ ... so I added these to the PythonPath for my Eclipse/PyDev project.
With the correct interpreter selected I then tried to run a file which runs fine on the command line: "> python3 functional_tests.py"... but I get
File "D:\apps\Python34\lib\site-packages\django\http\__init__.py", line 1, in <module>
from django.http.cookie import SimpleCookie, parse_cookie
File "D:\apps\Python34\lib\site-packages\django\http\cookie.py", line 5, in <module>
from django.utils.six.moves import http_cookies
ImportError: cannot import name 'http_cookies'
... to me this looks like a dependency thing... as though "pip install" handles dependency matters in a way just including a single folder doesn't.
Question boils down to this: what's the "proper" way to install a python module using PyDev?
several days later
wow... nothing? Nothing! I suppose this must mean that you either have to add dependencies manually or use something like Ant, Maven or Gradle within Eclipse itself. These latter are not my strong areas, even outside an IDE. Would still be nice to have an answer from a PyDev expert!
Well, pip install should work for PyDev (it should automatically recognize the dependency)...
I.e.: in your use case, the only folder that should be in the PYTHONPATH is D:\apps\Python34\lib\site-packages (and pip should install packages to that folder -- make sure you don't add extra folders for "D:\apps\Python34\lib\site-packages\django" nor anything else inside the site-packages to the PYTHONPATH).
If it's still not working, please check if the module django.utils.six.moves.http_cookies is indeed where you expect it to be. Also, you can print the PYTHONPATH being used in runtime with:
import sys
print('\n'.join(sorted(sys.path)))
To check if that's really what you expect.
When I try to import time I get : No module named time
I have tried other time modules(datetime and timeit) and they work fine. I decided to check my installation and I can't find time.py anywhere. I checked the Lib, Scripts, libs and include folders, but can't find it anywhere.
Anyone know what I can do to fix this? Maybe download the .py and put it in Lib myself?
I am using Python 3.3.5 with PyCharm IDE. Only extra scripts I've installed is EasyInstall and PRAW.
The import does work. When PyCharm said No module named time, I assumed I would get a compiler error and started trying to fix it.
However when I eventually just ran the code it worked fine. I expect PyCharm doesn't detect the time module as it's a dll and not a py as noted by Martijn in the comments. This is on PyCharm Community Edition 4.0.4.
I tried playing with virtualenv and a host of other things, but I eventually went to Preferences -> Build, Execution, Deployment -> Console -> Python Console, and in the "starting script" box, I added two lines:
sys.builtin_module_names.append('sys')
sys.builtin_module_names.append('time')
This got rid of errors I had with both sys and time. Once I did that, I even get autocomplete for both of those modules... weird.
I have been banging my head against the wall trying to get Exscript installed. After multiple failed attempts at doing it manually, I installed ActivePython and had success running "pypm install Exscript" from the cmd prompt.
I am now going through the Exscript documentation (found here https://github.com/knipknap/exscript/wiki/Python-API-Tutorial) and if I run the first example script I get an error:
>>> from Exscript.util.interact import read_login
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
from Exscript.util.interact import read_login
ImportError: No module named interact
So, I understand that this is saying that there is no module interact. How can I check this? Is there a way I can manually add this module? I would love to know WHY this module didnt come with the package, but that may be impossible to answer :)
Any and all help is greatly appreciated. Thank you
EDIT -
import Exscript.util works but if I try import Exscript.util.Interact I get the error. When I look in util.py I see an entry that says "from FooLib import Interact". I first thought it may just be a capitalization error (Exscript.util.interact vs util.Interact) but neither of those work. I am not sure where to go from here... :(
EDIT -
I have posted this question on the developers forums, hopefully he will have an answer for us. https://github.com/knipknap/exscript/issues/15
EDIT -
The developer suggested that I was using an old version and told me to download the latest. I had struggled installing the module manually so I googled how to easily install py modules. I found a writeup on easy_install.exe. I ran "c:\Python26>easy_install C:\Users\support\Desktop\lou\knipknap-exscript-v2.1-70-gf5583f3.tar.gz" from the cmd prompt, the module was installed (no errors) and now when i run the script it works.
Next challenge will be how to get these scripts to run as stand-alone exe's on users computers without Python installed :)
THANK YOU to everyone to commented I truely appreciate your help.
Lou
One common way packages are installed is as directories. So check your site-packages directory for an Exscript directory, and inside that there should be a util directory, and inside that there should be an interact.py file. Look for similar spellings in case the tutorial misspelled something.