How to import pygame, pyperclip? - python

I am fairly new to python but am having issues importing certain packages within my code. I try to import pyperclip aswell as pygame. I've installed them both manually and I've tried importing them using import pygame and import pyperclip and I get
"no module named 'pyperclip'"
and the same thing for pygame. I've tried opening by putting just import pygame and saved it to run it in the interactive shell and I've also just tried typing it into the interactive shell.
I'm running linux mint 17.3 and python 2.7.6
Has anyone else had this issue?
Any help would be appreciated. Za

I had the same problem. I am also new to Python and programming. I tried about 100 things, but what worked for me was typing the following in the command shell:
pip install pyperclip
That was it. However, I was using Windows' command module, so. . . you know. But it's worth a shot!
This link might help, too (it has Linux instructions, etc): https://github.com/asweigart/pyperclip

Related

Learning Python with Chromebook. Having trouble importing external modules into IDLE

I have had some issues with importing external modules into IDLE on chromebook.
For example I would like to start with termcolor. I was able to download termcolor through the linux shell using the command:
python3 -m pip install termcolor
It downloads into a folder:
./.local/lib/python3.7/site-packages
I would now like to use termcolor in IDLE.
I have not been able to successfully change the directory that termcolor gets downloaded into therefore it was difficult to access within IDLE. However, I was able to use the following command to access that directory:
import sys
sys.path.append(('./.local/lib/python3.7/site-packages'))
I was then able to import termcolor and use it a little. However, when I try to do something like:
print(termcolor.colored('hi'))
I get the result:
hi[0m
I would like to try and get everything sorted out since as I progress towards more advanced modules, I would like to not run into similar problems. I have though about getting a different laptop such as a mac to maybe simplify things since Chromebook may make things more difficult for beginners.
So my questions would be:
1) Can I add into IDLE pathbrowswer ./.local/lib/python3.7/site-packages?
2) How do I correct so I do not get hi[0m as a result?

cv2 and opencv Python troubleshooting install

I'm totally new to python. Currently I'm trying to install a packaged named cv2/openvc. Having migrated from Rstudio I'm trying to use rodeo in the same way for python. Python definitely seems less user friendly.
When I try to import the package from rodeo and I get following error:
However, when I run python from the windows cmd line and all works fine, I can even import cv2 and check the version.
Why is this and how can I fix it?
I can say the best thing you can do is to really know which python installation is being used by Rodeo. However, if you are in hurry you can install cv2 within the python interpreter by this code:
import sys
import subprocess
subprocess.call([sys.executable, "-m", "pip", "install", "opencv-python"])

install and use pygame on Mac Yosemite

I installed Pygame on my mac using Anaconda.
pip install pygame
>>>Requirement already satisfied: pygame in /anaconda/lib/python3.6/site-packages
The thing is, I do not know to use it now. When I run a simple file from my code editor it says:
File "/Users/julien/untitled5.py", line 1, in <module>
import pygame
ImportError: No module named pygame
any advice ? I tried to run pygame using spyder from the Ananconda Navigator bun it does not seem to work either.
The issue is that your IDE is looking in the wrong places for pygame. To see where it's looking for packages, run this script in the console for that IDE:
>>>import sys
>>>sys.path
This will show a list of paths where python looks for packages. /anaconda/lib/python3.6/site-packages won't be there, which is why you can't import it. What IDE are you using? Most are able to change their settings so that they can import from different places, see if you can do that, and put /anaconda/lib/python3.6/site-packages as part of the path.

Python on Windows error: python25.dll not found

I am running Python 2.7 on Windows 7 (on parallels on a Mac running Mountain Lion) and getting a strange error. It has happened both using Python(x,y) and the Enthought Python Distribution (paid version - 64-bit).
Running python from the command line initially works fine (and always does after rebooting the machine).
But, when I try to run my code at the command line as
python the_script.py
On the first try, I get this error window:
After that, I get the same error just from typing python at the command line.
If I specify the path as c:\python27\python the_script.py it works fine.
Here are all the modules I'm loading in my scripts:
import numpy as np
import subprocess as sub
import parallel_condor_Jacobian as pcj
import os
import shutil
In parallel_condor_Jacobian the following modules are loaded:
import numpy as np
import os
import subprocess as sub
Nothing really out of the ordinary I think!
Is one of these packages somehow dependent on python25.dll?
Fixes I have tried include totally removing python 2.7, reinstalling, and removing all python path stuff from my PATH environment variable and replacing them with c:\python27.
I'm really at a loss here. Happy to provide more relevant information.
remove the python.exe in the local folder ... and tell your colleagues to upgrade to at least 2.6 :P
and also tell them that the python exe is not portable :P

Using pygame on a mac?

I was trying to get pygame on my mac to work. I got it running in terminal. But I run into issues when trying to use it with netbeans or trying to run the file. It gives me the error
from pygame.locals import *
ImportError: No module named locals
any help? Thanks!
If you still want to use netbeans, I think you should take a look at ActivePython
Activepython basically lets you install different pythons on your machine and be able to select between them (there's a lot more features I'm sure).
My advice would be to go to the console and type
>python
>>> from pygame.locals import *
If that works, ctrl-c out and do a python -v to find out the version.
Once you have the version, you can use activepython to select that version by running:
sudo pysel [version]. For instance for python2.7:
sudo pysel 2.7
This should switch the python over and your netbeans should (hopefully) work with it.

Categories

Resources