How do I install Python packages/ wxPython on Mac OSX? - python

I'm very new to python and any non-basic computer functions in general, but I'm having a very basic problem and I can't figure out how to fix it. Any time I download a module from the internet and try to import it in python, I get an error message. For example, I just downloaded wxPython after being instructed to do so on a tutorial program for Python I've been using, and after entering "import wx" I got:
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
import wx
ImportError: No module named wx
How do I fix this so that python can find modules I download?
Thanks!!
Python version 2.7.3, and I downloaded wxPython from the download link on the website. Another thing I noticed: whenever I type in python setup.py install in the Terminal, I get:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
can't open file 'setup.py': [Errno 2] No such file or directory
Which seems to be another huge problem?

There are a few things you need to do to actually debug this:
Run python and check what version you are running.
type where python and figure out if you have multiple versions of python running at once.
With pip or easy_install, read the output to check where they are installing packages. It's somewhat likely that they are installing to the system-wide Python 2.6, as opposed to the version that you want it to be installed to (Python 2.7).
If you find any packages installed in the wrong place with 3, uninstall them with pip uninstall <packagename> and then specifically reinstall them to 2.7 with easy_install-2.7 or pip-2.7 install. If you don't see the option for easy_install-2.7 or pip-2.7, you need to install distribute and run its setup.py file with the specific version of Python you are using.
Make sure you are actually in the directory when running setup.py. For example, to install distribute, you need to cd into the appropriate directory to install.
Finally, a separate note: it's far easier to install packages with easy_install or pip, as opposed to downloading them separately. You should try doing that first. Again, distribute has more info.

Related

python cannot find module that is installed on windows

I have installed the requests module
C:\Python34\Scripts\easy_install.exe requests
i got to the folder location
C:\Python34\Lib\site-packages\requests-2.13.0-py3.4.egg\requests
I have a path variable in system
C:\Python34\Lib\site-packages
yet when i run my script
C:\Users\beast\Desktop>update.py
I get the error No module named 'requests'
Traceback (most recent call last):
File "C:\Users\beast\Desktop\plex_playlist_update.py", line 17, in <module>
import requests
ModuleNotFoundError: No module named 'requests'
I tried installing using pip just in case
python -m pip install requests
Requirement already satisfied: requests in c:\python34\lib\site-packages\requests-2.13.0-py3.4.egg
I am new to python and I cant find an answer anywhere.
UPDATE:
I found a command to check my python search location.
C:\Users\beast\Desktop>python -c "import site; print(site.getsitepackages())"
['C:\\Python34', 'C:\\Python34\\lib\\site-packages']
I think it has to do with C:\Python34 vs C:\python34? How do i check or fix this?
The problem here is maybe because of the different versions of python installed.
If you are a Windows user, you can go to Path in Environment variables and remove the paths to unnecessary versions of python (if any). Modules installed for one version of python won't work in another version.
So I ended up going with python environment. Per python documentation it is the way to go anyway. The below command are run on the root folder of the python app.
py -m venv env
then
./env/Scripts/activate
I then ran my pip upgrade and everything is working. Obviously this did not fix it computer wide. just for my python app. But from documentation this is better because of version control of the whole enviroment.
This creates a "env" folder at the root which will have all the packages installed. Need to install all requirements again or use the requirements.txt file.

Installing and importing Python Modules onto OS X

I've been trying for a couple of hours already. It seems IDLE can't find any third-party module. I am a Python beginner.
Here is some info about my system:
OSX version: 10.11.5
python version: Python 2.7, Python 3.4, Python 3.5
The initial installation using pip (among other methods) seems to work fine. When I repeat the installation, terminal responds with:
Requirement already satisfied (use --upgrade to upgrade): pyperclip in
./anaconda/lib/python3.4/site-packages
However, when I go to IDLE (Python 3.4) and try to import the module, IDLE responds with:
Traceback (most recent call last): File "", line 1, in
import pyperclip ImportError: No module named 'pyperclip'
I have read that it may have something to do with my PATH or some virtual environment. I’ll be frank, I’m not sure what to make of these as they seem beyond my current ability.
This inability to import modules is becoming an almost insurmountable roadblock to advancing with Python. If you can offer any ideas on what I can do or can ELI5 the solution, I am forever in your debt?
It seems you are using conda, but you are trying to install the pyperclip module with pip. Have you tried running conda install pyperclip?
As stated here:
Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side but they do not interoperate either.

checking virtual environment modules

So I am following this tutorial and I am about to give up since i am working on a windows machine and I am pulling my hair out finding equivalencies.
I have a virtual environment, but when I try to run my code it dosent appear to be finding the local dependancies!!
(venv) PS C:\Users\Vince\skellys\Flask_skelly\venv> python Bartender_no_ui.py
Traceback (most recent call last): File "Bartender_no_ui.py", line 7, in <module>
import lxml
ImportError: No module named lxml
How can i check if the dependencies are there and how do i make sure my code is running from venv?? Am I just to much of a noob to be trying this tutorial anyway??
maybe relevant details- I had to use Conda rather than pip to install lxml, because pip couldnt get the dependencies of libxml2 and libxslt, but I get no module error for the other modules that I installed in the venv using pip as well
If you do
pip freeze
That should show you what modules you have installed in your virtualenv as long as you have it active.
Seeing as how you are working on windows I'd check out this site Its what I followed when I first got started.
Haven't used Conda much myself so not familiar with how it works but I'm guessing that won't install to your virtualenv. If you download lxml from here you should be able to install it into your virtualenv on windows.
its not the best solution but I figured out a hack around - I copied lxml from my c:\anaconda\pkgs folder. Code appears to be running fine. figures.

no module named 'numpy' (windows 7, python 3.4.3, numpy-1.9.2)

Please only respond to this post if you use Python on Windows, rather than Mac or Linux.
Error message:
>>> import numpy
Traceback (most recent call last):
File "stdin", line 1, in <module>
ImportError: No module named 'numpy'
Questions:
Regarding windows 7, python 3.4.3 and numpy-1.9.2, are there any
conflicts that would prevent these from working together?
Into which directory (please write out the complete directory path
starting with "C:") should I extract the contents of the numpy zip
file?
What is the exact command that I need to type into python command
prompt in order to install numpy?
Thanks in advance for your assistance
I was also facing this issue where in I tried using
import numpy
But it has given me error "ImportError: No module named 'numpy'"
I installed numpy using "C:\user>python -mpip install numpy" and it was successfully installed.
However I was again getting the same error
Then I checked that the path where in numpy was intalled was not listed in
import sys
print(sys.path)
Then I appended my path wherein numpy was installed using ">>> sys.path.append(r"C:\Users\xxxx\AppData\Roaming\Python\Python38\site-packages").
The above command worked fine, still problem not resolved then I restarted my python session again.
Finally it worked..!!!!(As after every append we have to restart our python session).
1) No there isn't.
2) You can use pip. pip install numpy
If you don't have pip installed, install it, its the most often used way of installing python packages. Yes it is possible to do under windows.
3) Once you have the python command prompt, you already have python installed.
1) no
2) It doesn't actually matter as pip or the installer will figure that out for you. However, just so you know, pip or whatever will install numpy into your site-packages folder.
3) I recommend downloading the NumPy installer from SourceForge:
http://sourceforge.net/projects/numpy/files/NumPy/1.9.2/
Then you don't have to worry about having the right compiler installed. However, if you want to use pip, then you'll need to install the appropriate compiler. This is documented at the following locations:
Microsoft Visual C++ Compiler for Python 3.4
https://matthew-brett.github.io/pydagogue/python_msvc.html
I'm not even close to an expert on Python. That said, I like the notion of "keep it simple." I chose to install a Python distribution that already includes numpy. Specifially I installed Python(x,y). Everything seems to be working just fine right after install. I appreciate all those who commented on my question. Thanks

Python34\Scripts folder configuration after installation

In the attempt to get Easy_Install working with Python34 and Python27 I've exhausted the options listed in the documentation.
Is there a way to add the Python\34\Scripts folder so I stop getting the following error?
>>> easy_install numpy
File "<stdin>", line 1
easy_install numpy
^
SyntaxError: invalid syntax
AND
>>> easy_install
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'easy_install' is not defined
>>>
You are running shell commands from the Python REPL, not from the Windows command line. Quit the REPL by typing quit(), exit(), or hitting CtrlD. Open a Windows command prompt by hitting WinR, typing cmd, and hitting Enter. easy_install should now work, although for most use cases (unless you're installing from an egg), pip should be sufficient. It is already installed with Python 3.4 and 2.7.9, and can otherwise be installed by googling install pip and following the first link. pip install numpy is definitely the preferred way to go, as pip supports wheels, which more and more packages (including numpy) are uploading to PyPI.
Alternatively, search Christoph Gohlke's Python Extension Packages for Windows Repository for the package you're looking for. The version of numpy there comes statically linked to Intel's high-performance MKL library, as do a number of numpy-dependent packages like scipy and matplotlib. Simply download the appropriate .whl files from Gohlke's site, run pip install package_name_version_whatever.whl, and you're good to go.

Categories