pyperclip has no attribute copy - python

When i run this code
import pyperclip
pyperclip.copy('German')
pyperclip.paste()
I get the error
Traceback (most recent call last):
File "C:/Windows/System32/pyperclip.py", line 1, in <module>
import pyperclip
File "C:/Windows/System32\pyperclip.py", line 2, in <module>
pyperclip.copy('German')
AttributeError: module 'pyperclip' has no attribute 'copy'
I have installed pyperclip using pip
I have tried reinstalling Pyperclip but it does nothing.

You called your module pyperclip by naming your file pyperclip.py. Therefore, your import pyperclip is actually a recursive import (importing your own module) and will not work.
To avoid this, just don't name your module the same as a library you use.

instead of pyperclip I have decided to use os:
os.system("echo '%s' | pbcopy" % STRING_NAME_HERE

I recommend start reading #nneonneo answer first and if the below solutions did not fix the problem, try this one:
In the same directory I noticed that I have paperclip.py file. I just renamed it and it stopped showing circular import error

Firstly, Have you install pyper clip module or not. if you have not install pyperclip module then it will not work

Related

Python sound modules not working (Circular Import)

After installation of playsound and simpleaudio modules to try simple commands in order to play some audio files I always get the following message.
playsound: ImportError: cannot import name 'playsound' from partially initialized module 'playsound' (most likely due to a circular import) (/Users/joaosoares/Documents/PySound/playsound.py)
simpleaudio:AttributeError: partially initialized module 'simpleaudio' has no attribute 'WaveObject' (most likely due to a circular import)
I am currently using python 3.8.1, I've tried to create a new environment using pipenv and the problem persists. I got it to work the very first time I installed playsound. The problem might came after I had to install AppKit.NSSound as needed to run simplesound. My problem may be obvious and I apologise in advance if my issue isn't clarified I started to use python very recently.
I am following this tutorial
The only way i can reproduce your error is if i create a file called playsound.py
from playsound import playsound
playsound('myfile.wav')
ERROR
Traceback (most recent call last):
File "C:/Users/Chris/PycharmProjects/stackoverflow/stackoverflow.py", line 1, in <module>
from playsound import playsound
File "C:\Users\Chris\PycharmProjects\stackoverflow\playsound.py", line 1, in <module>
from playsound import playsound
ImportError: cannot import name 'playsound' from partially initialized module 'playsound' (most likely due to a circular import) (C:\Users\Chris\PycharmProjects\stackoverflow\playsound.py)
In your question your error specifically says your file is called playsound.py
/Users/joaosoares/Documents/PySound/playsound.py
rename this to something else otherwise it will try to import its self
There is Error in playsound Module So I has solved it for beginners
Hope so it's useful for you
Write This Command in Terminal that is provided in the image
https://i.stack.imgur.com/j6zcN.png
And Then Again Run the Python File and the Error is Solved
Now you can play sound using playsound module
https://i.stack.imgur.com/VQiNN.png
Note : Use double \ in path if you are a windows user else use \ in Mac and also enter Correct Path of song
just uninstall the current version by typing:
pip uninstall playsound
then install the older version by typing:
pip install playsound==1.2.2
just remove that playsound (use another name) and you are done

What is meant by `import coding`?

I am working with elffile python module/library. There is one line of code that is giving the following error
Traceback (most recent call last):
File "elffile.py", line 36, in <module>
import coding
ImportError: No module named coding
I could not find any python file or class named coding. Also, I didn't find anything on the internet regarding import coding.
Import is when you import modules to use in your coding.
If it cant find the module you probably have to install it. The easiest way to do this is to use pip.
Write: pip install coding (or pip3) and it will install the module.

Python third party Module global import

i'm currently into learning a bit of python and i want to import the paperclip third party module into my python file.
Yes, i already installed the pyperclip module with
pip install pyperclip.
if i create a file on my desktop, i get an error which says
Traceback (most recent call last):
File "test.py", line 1, in <module>
import pyperclip
ImportError: No module named pyperclip
However if i put the test.py in my python folder, it runs.
The question now is, is there a way to make all my installed modules available on a global scope ? I just want to have my file e.g. on my Desktop and run it without having import issues.
Thank you.
Greetings
Edit: I'm working on a Mac, maybe this leads to the problem
Found the problem.
The pip installautomatically used pip3.5 install
whereas python test.pydidn't use python3.5 test.py
Thank you #Bakurìu
Is there a way i can define python3.5as python?
You can do this :
pip3.5 install paperclip
pyperclip is install but not paperclip

win32 Python - pythoncom error - ImportError: No module named pywintypes

I am trying to import pythoncom, but it gives me this error: Traceback (most recent call last):
File "F:/Documents and Settings/Emery/Desktop/Python 27/Try", line 2, in
import pythoncom
File "F:\Python27\lib\site-packages\pythoncom.py", line 2, in
import pywintypes
ImportError: No module named pywintypes
I reinstalled Python win32, but it still doesn't fix it. Any help? Also, I am trying to access the pythoncom.PumpMessages() method, an alternative would be nice as well.
If you are using an IDE like I am (PyCharm), you should go the where the Python is installed e.g C:\Users\***\AppData\Local\Programs\Python\Python37\Lib\site-packages
In this folder check for the folder name pywin32. Copy that folder and paste it to C:\Users\***\PycharmProjects\project\venv\Lib\site-packages. After that restart your IDE, then it will import the pywin32 as it did in my case. I hope it helps.
pip install --upgrade pywin32==228

import win32com.client error

When I try to:
from win32com.client import Dispatch
in Python I get the error:
Traceback (most recent call last): File "", line 1, in
from win32com.client import Dispatch File "C:\Users\Lynn\Documents\2e
master\masterproef\python\lib\site-packages\win32com__init__.py",
line 5, in
import win32api, sys, os ImportError: No module named win32api
I already tried to copy the files pythoncom27.dll and pythonwintypes27.dll to python\lib\site-packages\win32 and python\lib\site-packages\win32com but that didn't help.
I've installed pywin32-217.win32-py2.7.‌exe from http://www.lfd.uci.edu/~gohlke/pythonlibs/
I've also already searched for duplicated files with no success either.
I've installed other packages (numpy, ...) before and they all worked perfectly.
I'm using Python 2.7
I've solved my problem :-) After some more google-ing I finally found something that helped:
http://www.python-forum.org/pythonforum/viewtopic.php?f=15&t=17163&p=156600
When I ran the .exe file with " selecting fix compatibility problem" everything magically worked!
This fixed the issue for me
https://pypi.python.org/pypi/pypiwin32
pip install pypiwin32
That will work in a virtualenv, or with tox, etc

Categories

Resources