pip install for Python 3 in virtualenv on Mac OSX? - python

I can pip install and import just about any package on my Mac in a virtual environment, doing the following:
Setting up the virtual environment:
Last login: Mon Oct 3 18:47:06 on ttys000
me-MacBook-Pro-3:~ me$ cd /Users/me/Desktop/
me-MacBook-Pro-3:Desktop me$ virtualenv env
New python executable in /Users/me/Desktop/env/bin/python
Installing setuptools, pip, wheel...done.
me-MacBook-Pro-3:Desktop me$ source env/bin/activate
Let's pip install pandas:
(env) me-MacBook-Pro-3:Desktop me$ pip install pandas
Collecting pandas
Using cached pandas-0.19.0-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting pytz>=2011k (from pandas)
Using cached pytz-2016.7-py2.py3-none-any.whl
Collecting python-dateutil (from pandas)
Using cached python_dateutil-2.5.3-py2.py3-none-any.whl
Collecting numpy>=1.7.0 (from pandas)
Using cached numpy-1.11.1-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting six>=1.5 (from python-dateutil->pandas)
Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: pytz, six, python-dateutil, numpy, pandas
Successfully installed numpy-1.11.1 pandas-0.19.0 python-dateutil-2.5.3 pytz-2016.7 six-1.10.0
Great! Now, let's see if it works in Python 2.7:
(env) me-MacBook-Pro-3:Desktop me$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> exit()
pandas loaded in 2.7, now let's try 3.5:
(env) me-MacBook-Pro-3:Desktop me$ python3
Python 3.5.0a4 (v3.5.0a4:413e0e0004f4, Apr 19 2015, 14:19:25)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pandas'
>>>
:(
I'm running OSX El Capitan 10.11.6. How can I import non-builtin modules in a virtual environment? I really would rather use Python 3...

Try using virtualenv --python=$(which python3) env to create the virtual environment.
When you create a virtualenv by default it uses the python binary it was installed with. So if you did pip install virtualenv on a system where python2.7 was installed first, then virtualenv will use python2.7 by default. You'll want to create separate virtual environments for different python versions.

Related

Inconsistent python module version

I got inconsistent module version number of selenium.
I installed selenium 3.141.0 offline:
>pip download selenium==3.141.0
>pip install --no-index --find-links E:\pip-selenium\3.141.0 selenium
Collecting selenium
Requirement already satisfied: urllib3 in c:\python27\lib\site-packages (from selenium)
Installing collected packages: selenium
Successfully installed selenium-3.141.0
Yet I get 3.4.0 in __version__ variable:
>python
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
>>> print selenium.__version__
3.4.0
If I run pip list it says the version is 3.141.0:
>pip list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
comtypes (1.1.4)
mysql-python (1.2.3)
pip (9.0.3)
pyodbc (4.0.23)
pywin32 (223)
pywinauto (0.6.4)
selenium (3.141.0)
setuptools (39.0.1)
six (1.11.0)
urllib3 (1.25.3)
What's happening?
This happens because I have two versions of selenium installed. Check sys.path and look for duplicate packages in those directories.

Python elasticsearch_dsl module not found in Python3 running on Windows 10 Ubuntu after successful installation

I successfully install the elasticsearch_dsl module in Windows 10 Ubuntu, but the module cannot be found in Python3. Can anyone shed light on what the problem might be?
It works fine when I run in Anaconda, but because most of my code has Unix-style file paths, I really want it to work on ubuntu.
$ pip install elasticsearch_dsl
Collecting elasticsearch_dsl
Using cached https://files.pythonhosted.org/packages/77/95/aa96ac42bf7cf8d56d4c7330f4fa5c1b2c460efa7ad2e9ba183bae823b0b/elasticsearch_dsl-7.0.0-py2.py3-none-any.whl
Collecting six (from elasticsearch_dsl)
Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Collecting ipaddress; python_version < "3.3" (from elasticsearch_dsl)
Using cached https://files.pythonhosted.org/packages/fc/d0/7fc3a811e011d4b388be48a0e381db8d990042df54aa4ef4599a31d39853/ipaddress-1.0.22-py2.py3-none-any.whl
Collecting python-dateutil (from elasticsearch_dsl)
Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting elasticsearch<8.0.0,>=7.0.0 (from elasticsearch_dsl)
Using cached https://files.pythonhosted.org/packages/ae/43/38329621bcca6f0b97e1cc36fb3cef889414a1960fcdc83a41e26b496634/elasticsearch-7.0.2-py2.py3-none-any.whl
Collecting urllib3>=1.21.1 (from elasticsearch<8.0.0,>=7.0.0->elasticsearch_dsl)
Using cached https://files.pythonhosted.org/packages/e6/60/247f23a7121ae632d62811ba7f273d0e58972d75e58a94d329d51550a47d/urllib3-1.25.3-py2.py3-none-any.whl
Installing collected packages: six, ipaddress, python-dateutil, urllib3, elasticsearch, elasticsearch-dsl
Successfully installed elasticsearch-7.0.2 elasticsearch-dsl-7.0.0 ipaddress-1.0.22 python-dateutil-2.8.0 six-1.12.0 urllib3-1.25.3
$ python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import elasticsearch_dsl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'elasticsearch_dsl'
>>>
Expected result is that the module would be recognized, and import properly. Actual result is ModuleNotFoundError. Thanks for any help.
pip3 install elasticsearch_dsl worked. Apparently pip3 is required for python3 at least in this case.
This is the pip issues.
python3 -m pip show elasticsearch_dsl
Then you get the PATH
Edit you Bash_profile
Type
sudo vim ~/.bash_profile
and append the the PATH
export PATH="$PATH:[elasticsearch_dsl PATH]"

Could not find a version that satisfies the requirement ruamel (from versions: ) No matching distribution found for ruamel

here is the python version:
Python 3.6.5
and I want to install ruamel with:
pip3 install ruamel
but I can't install it:
(venvpython3) d3alg#ubuntu-59:/$ python
Python 3.6.5 (default, Apr 1 2018, 05:46:30)
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(venvpython3) d3alg#ubuntu-59:/$ pip3 install ruamel
Collecting ruamel
Could not find a version that satisfies the requirement ruamel (from versions: )
No matching distribution found for ruamel
What am I doing wrong?
If you search PyPI for ruamel, you'll see that there is no package with that name. All available packages have that string as a namespace (ruamel.). You actually have to select each package you want to install (although some will depend on others and pull in multiple "ruamel." namespaced packages):
pip3 install -y ruamel.yaml

update python module while it is active

Is it possible to update a python module while it is used in a running script?
The situation is the following:
1) I have a script running using pandas 0.15.2. It is a long data processing task and should continue running for at least another week.
2) I would like to run, on the same machine, another script, which requires pandas 0.16.
Is it possible for me to do 2) without interrupting 1)?
If the script is still running, it's likely that replacing the dependency will not affect it at all - the code will already be in memory.
Still, it's better to be safe than sorry. I would install the other script inside a virtualenv, in which you can install whichever versions of modules you want without affecting anything else.
Install pandas 0.16 in an alternate location. For example on my system I made the directory /Users/kteague/pytest/ for installation. Then I used the --target option in pip to install into that location:
$ pip install --target /Users/kteague/pytest pandas
Collecting pandas
Using cached pandas-0.17.0-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting pytz>=2011k (from pandas)
Using cached pytz-2015.6-py2.py3-none-any.whl
Collecting python-dateutil>=2 (from pandas)
Using cached python_dateutil-2.4.2-py2.py3-none-any.whl
Collecting numpy>=1.7.0 (from pandas)
Using cached numpy-1.10.1-cp35-cp35m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl
Collecting six>=1.5 (from python-dateutil>=2->pandas)
Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: pytz, six, python-dateutil, numpy, pandas
Successfully installed numpy pandas python-dateutil pytz six-1.9.0
Now you can export your PYTHONPATH to point to that location first. Scripts run from a terminal where the PYTHONPATH=/Users/kteague/pytest will use pandas 0.1.7 over whatever version of pandas is installed in the default site-packages directory.
$ export PYTHONPATH=/Users/kteague/pytest/
Use setuptools from the python interpreter to ensure your terminal is importing the version of pandas that you want:
$ python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 12 2015, 11:00:19)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pkg_resources
>>> pkg_resources.require("pandas")[0].version
'0.17.0'

really simple pip python-twitter issue; can't import twitter

I don't know what I'm doing wrong here:
Sun Oct 14$ pip install python-twitter
Requirement already satisfied (use --upgrade to upgrade): python-twitter in /Library/Python/2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): setuptools in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python (from python-twitter)
Requirement already satisfied (use --upgrade to upgrade): simplejson in /Library/Python/2.7/site-packages (from python-twitter)
Requirement already satisfied (use --upgrade to upgrade): oauth2 in /Library/Python/2.7/site-packages (from python-twitter)
Requirement already satisfied (use --upgrade to upgrade): httplib2 in /Library/Python/2.7/site-packages (from oauth2->python-twitter)
Cleaning up...
Sun Oct 14$ python
Python 2.7.2 (default, Nov 17 2011, 13:22:48)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import twitter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named twitter
>>>
Do I need to do a virtualenv? What else could be going on? Sorry for my lack of understanding but any help is appreciated.
edit #1
trying to get tweepy working but.... possibly might have two versions of Python 2.7 here
Sun Oct 14$ pip install --upgrade tweepy
Requirement already up-to-date: tweepy in ./tweepy-1.11-py2.7.egg
Cleaning up...
Sun Oct 14$ python
Python 2.7.2 (default, Nov 17 2011, 13:22:48)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tweepy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tweepy
>>>
I think I might have two versions of Python 2.7 installed; one via homebrew and the Apple default. Is it possible that the homebrew install would put packages in /Library/Python/2.7/site-packages?
again, thx in advance
From what I've read, python-twitter:
Relies on Basic-Auth which Twitter switched off sometime between
August and September (2010). Only OAuth is supported by the API, and
python-twitter doesn't support this.
UPDATE: I just tried installing python-twitter using the exact same method you used and I am unable to import it as well. After doing some research I came across Python Twitter Tools, which I believe is python-twitter's replacement.
Installing twitter requires setuptools. It's just easy_install twitter to install it from the web.

Categories