Specifying which python version to pip install to - python

I'm having troubles when trying to download and run packages within python, using pip install. Often pip will tell me that I have the package downloaded, but when I try to use the function it gives me an error and says 'no such file or directory'. It seems to me that I am using 2.7.10 and that is where pip is trying to install to, but I can't get why this isn't working
Peters-MBP:~ pete$ python import plotly
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python: can't open file 'import': [Errno 2] No such file or directory
Peters-MBP:~ pete$ pip install plotly
Requirement already satisfied (use --upgrade to upgrade): plotly in ./Library/Python/2.7/lib/python/site-packages
Collecting pytz (from plotly)
Using cached pytz-2016.3-py2.py3-none-any.whl
Requirement already satisfied (use --upgrade to upgrade): requests in ./Library/Python/2.7/lib/python/site-packages (from plotly)
Collecting six (from plotly)
Using cached six-1.10.0-py2.py3-none-any.whl
Installing collected packages: pytz, six
Successfully installed pytz-2016.3 six-1.10.0
You are using pip version 8.1.0, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Peters-MBP:~ pete$ python --version
Python 2.7.10
Peters-MBP:~ pete$ python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

Try to upgrade 'pip install --upgrade pip'
Then try to upgrade also plotly and check it again.
Please post if the plotly module is visible in the Python27 installation folder.
In addition you should go inside the "python interpreter" to import a module.
Just try to
> python
import plotly

You can’t just import a module on the command line like that(!!!):
$ python import plotly
Instead, do this:
First start the interactive Python interpreter:
$ python
Then, at the Python prompt, import your installed module:
>>> import plotly
Or, of course, put the import statement in a script and execute that script.
Edit: If you try to run python install plotly at the shell prompt, as you did, the Python interpreter will look for a script called install in the current directory, in order to execute it. Since no such script exists, it gives the error can't open file 'import': [Errno 2] No such file or directory.

Related

Why does pip install not work for catboost? Problem with python distribution

I have to install catboost but can not make it by pip install catboost. Pip sad 'No matching distribution found for catboost' but that is not as i think.
I read this question Why does pip install not work for catboost?
and made sure that i had use pyhon x64, and can install librareis using pip.
The cmd output:
C:\Users\uname\AppData\Local\Programs\Python\Python311>python.exe -m pip install cx_oracle
Collecting cx_oracle
Using cached cx_Oracle-8.3.0-cp311-cp311-win_amd64.whl
Installing collected packages: cx_oracle
Successfully installed cx_oracle-8.3.0
C:\Users\uname\AppData\Local\Programs\Python\Python311>python
Python 3.11.2 (tags/v3.11.2:878ead1, Feb 7 2023, 16:38:35) \[MSC v.1934 64 bit (AMD64)\] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cx_Oracle
>>> exit()
C:\Users\uname\AppData\Local\Programs\Python\Python311>python.exe -m pip install catboost
ERROR: Could not find a version that satisfies the requirement catboost (from versions: 0.1.1)
ERROR: No matching distribution found for catboost
May by the problem in PATH because i have not the administre privilege to check this out but during the pyhton instalation i confirmed adding python to path.
Pip version is:
C:\Users\uname\AppData\Local\Programs\Python\Python311>python -m pip -V pip 23.0 from C:\Users\uname\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip (python 3.11)
What should i do?
I get the solution it's very simple, catboost is not supported for python 3.11 now
Check here https://pypi.org/project/catboost/#files

How to pip uninstall a package installed using a git project URL?

I've tried following the installation instructions for the BlueJeans meetings REST API (https://github.com/bluejeans/api-rest-meetings/tree/master/libs/python), using the command
pip install git+https://github.com/bluejeans/api-rest-meetings.git#pip-repo
The pip freeze command confirms that I've installed it:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip freeze
BlueJeansMeetingsRestApi==1.0.0
certifi==2018.4.16
python-dateutil==2.7.3
six==1.11.0
urllib3==1.23
However, in the iPython shell, I'm unable to import BlueJeansMeetingsRestApi:
Kurts-MacBook-Pro-2:~ kurtpeek$ ipython
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 05:52:31)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import BlueJeansMeetingsRestApi
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-0891de0c20ce> in <module>()
----> 1 import BlueJeansMeetingsRestApi
ModuleNotFoundError: No module named 'BlueJeansMeetingsRestApi'
This is in my local environment, but I've also installed it in a Pipenv environment, in which case I was required to provide an egg, which I did by appending #egg=BlueJeansMeetingsRestApi to the Git project URL. If I do this straight away, I get 'requirement already satisfied':
Kurts-MacBook-Pro-2:~ kurtpeek$ pip install git+https://github.com/bluejeans/api-rest-meetings.git#pip-repo#egg=BlueJeansMeetingsRestApi
Requirement already satisfied: BlueJeansMeetingsRestApi from git+https://github.com/bluejeans/api-rest-meetings.git#pip-repo#egg=BlueJeansMeetingsRestApi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (1.0.0)
Requirement already satisfied: urllib3>=1.15 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (1.23)
Requirement already satisfied: six>=1.10 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (1.11.0)
Requirement already satisfied: certifi in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (2018.4.16)
Requirement already satisfied: python-dateutil in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from BlueJeansMeetingsRestApi) (2.7.3)
Therefore, I'd like to try to first uninstall BlueJeans and re-install it specifying the egg. However, if I try to uninstall it with the same project URL, I get the following error:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip uninstall git+https://github.com/bluejeans/api-rest-meetings.git#pip-repo
You must give at least one requirement to uninstall (see "pip help uninstall")
By the way, I'm using Python 3.7.0 (pip is an alias for pip3).
I have two questions:
Why is import BlueJeansMeetingsRestApi not working in the first place?
How can I uninstall it?
To uninstall a package just use
pip uninstall BlueJeansMeetingsRestApi
if there is some configuration issue with IPYTHON you can encounter such errors.
But if you are running short for time, i would suggest got with direct python shell command shell by using,i think this should work when you try import it into a file.
python <filename>.py
please check and let me know.
To summarize CoderRambo and tgikal's responses, yes, I was able to uninstall BlueJeansMeetingsRestApi in that fashion:
Kurts-MacBook-Pro-2:~ kurtpeek$ pip uninstall BlueJeansMeetingsRestApi
Uninstalling BlueJeansMeetingsRestApi-1.0.0:
Would remove:
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/BlueJeansMeetingsRestApi-1.0.0-py3.7.egg-info
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/BlueJeansMeetingsRestApi/*
/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/test/*
Proceed (y/n)? y
Successfully uninstalled BlueJeansMeetingsRestApi-1.0.0
At the root of the problem, however, was that iPython was running on Python 3.6, whereas BlueJeans was installed on Python 3.7. I confirmed this by using which ipython:
Kurts-MacBook-Pro-2:~ kurtpeek$ which ipython
/Library/Frameworks/Python.framework/Versions/3.6/bin/ipython
I ran pip install ipython, and now it points to Python 3.7:
Kurts-MacBook-Pro-2:~ kurtpeek$ which ipython
/Library/Frameworks/Python.framework/Versions/3.7/bin/ipython
I then re-installed the BlueJeans REST API (without specifying an egg), and now I'm able to import it:
Kurts-MacBook-Pro-2:~ kurtpeek$ ipython
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.4.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import BlueJeansMeetingsRestApi
In [2]:

Am I importing a package from conda wrong in my python script?

Heyo! I know this may look like a duplicate question of this question, but there is a little difference. I want to import the whole package, not just one or a groups of functions. When I import packages from Anaconda, and try to import them into a python script, I get ErrorModuleNotFound. I might be importing this wrong, so here is the information:
I am using Python 3.6 and conda 4.3.21.
Anaconda packages can be found in this directory: C:\ProgramData\Miniconda3
What I put into the Anaconda Prompt: pip install wikipedia (It installed successfully...)
Directory of my Python Script: C:\Users\aglin\Desktop\test.py
Conda env list: root * C:\ProgramData\Miniconda3
Path of Python.exe C:\Users\aglin\AppData\Local\Programs\Python\Python36-32\python.exe and C:\ProgramData\Miniconda3\python.exe
What my Python Script contains:
import wikipedia
print (wikipedia.summary("Windows OS"))
win = wikipedia.page("New York")
win.content
Error I'm getting:
================== RESTART: C:\Users\aglin\Desktop\test.py ==================
Traceback (most recent call last):
File "C:\Users\aglin\Desktop\test.py", line 1, in <module>
import wikipedia
ModuleNotFoundError: No module named 'wikipedia'
My question: How can I import the package wikipedia without getting this error? If it helps, "Wikipedia API for Python's Documentation" can be found here. Also, I'm pretty new to Python, so if I need to do anything specific or look at documentation, please tell me. Thanks! :D
Here are the usual steps to create an environment in conda, putting a version of Python into it, and importing a library into it afterwards.
The steps are:
conda create --name Py36 python=3.6
activate Py36
pip install wikipedia
You will notice that, at the end of the display, it's possible to open the Python interpreter and import wikipedia.
Microsoft Windows [Version 10.0.16299.125]
(c) 2017 Microsoft Corporation. All rights reserved.
C:\scratch>conda create --name Py36 python=3.6
Fetching package metadata .............
Solving package specifications: .
Package plan for installation in environment C:\ProgramData\Miniconda3\envs\Py36:
The following NEW packages will be INSTALLED:
certifi: 2017.11.5-py36hb8ac631_0
pip: 9.0.1-py36h226ae91_4
python: 3.6.3-h3b118a2_4
setuptools: 36.5.0-py36h65f9e6e_0
vc: 14-h2379b0c_2
vs2015_runtime: 14.0.25123-hd4c4e62_2
wheel: 0.30.0-py36h6c3ec14_1
wincertstore: 0.2-py36h7fe50ca_0
Proceed ([y]/n)? y
#
# To activate this environment, use:
# > activate Py36
#
# To deactivate an active environment, use:
# > deactivate
#
# * for power-users using bash, you must source
#
C:\scratch>activate Py36
(Py36) C:\scratch>pip install wikipedia
Collecting wikipedia
Collecting beautifulsoup4 (from wikipedia)
Using cached beautifulsoup4-4.6.0-py3-none-any.whl
Collecting requests<3.0.0,>=2.0.0 (from wikipedia)
Using cached requests-2.18.4-py2.py3-none-any.whl
Collecting urllib3<1.23,>=1.21.1 (from requests<3.0.0,>=2.0.0->wikipedia)
Using cached urllib3-1.22-py2.py3-none-any.whl
Collecting idna<2.7,>=2.5 (from requests<3.0.0,>=2.0.0->wikipedia)
Using cached idna-2.6-py2.py3-none-any.whl
Requirement already satisfied: certifi>=2017.4.17 in c:\programdata\miniconda3\envs\py36\lib\site-packages (from requests<3.0.0,>=2.0.0->wikipedia)
Collecting chardet<3.1.0,>=3.0.2 (from requests<3.0.0,>=2.0.0->wikipedia)
Using cached chardet-3.0.4-py2.py3-none-any.whl
Installing collected packages: beautifulsoup4, urllib3, idna, chardet, requests, wikipedia
Successfully installed beautifulsoup4-4.6.0 chardet-3.0.4 idna-2.6 requests-2.18.4 urllib3-1.22 wikipedia-1.4.0
(Py36) C:\scratch>python
Python 3.6.3 |Anaconda, Inc.| (default, Nov 8 2017, 15:10:56) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wikipedia
>>> ^Z
(Py36) C:\scratch>

ModuleNotFoundError: No module named 'bs4'

I'm still super new to coding! Trying to learn from online tutorials, but I seem to be stuck on the first step! I think I installed bs4, but it's not showing up in python3, is it installed in the wrong place?
robbie$ sudo -H pip install bs4
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /Library/Python/2.7/site-packages (from bs4)
Robbies-MBP:~ robbie$ python3
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
Any help would be greatly appreciated :)
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
You have the module installed for Python 2.7, however you're using and trying to import it with Python 3.6.
You have to use pip3 like you use python3.
If you are using python 3 then you shoud use pip 3. In order to install it in ubuntu:
sudo apt install python3-pip
And then use the following command for installing the module bs4:
pip3 install bs4
go to the bottom left of your vs code and select python 3.9.1 64 bit (depending on the version of your python). it'll work.
it works for me
Just a quick note but a lot of times when this happens and you are running python3 and you used pip3 to install bs4 or another module but are running two different versions of python3 (eg 3.4 and 3.6). Sometimes just doing a normal update in a distro like CentOS installs a newer version of python, but not the corresponding pip.
Take for example here where a user is running python3.6 but all modules are installed only for python3.4 and there is no pip3.6 available.
http://realtechtalk.com/python_ModuleNotFoundError_No_module_named_bs4_even_though_you_have_the_module-2267-articles
I was having the same issue but managed to solve it with custom install script in the code. This tries to import and if it fails, automatically installs it
def safe_import(module):
try:
exec(f'import {module}')
globals()[module] = eval(module)
except ModuleNotFoundError as err:
import os
os.system(f'pip install {module}')
exec(f'import {module}')
globals()[module] = eval(module)

Python interpteter can't find module in virtualenv, but pip sees it and won't install

I'm trying to use the pytools module within the virtualenv created by Nervana for their Neon deep learning package, but can't seem to either find pytools or pip it. When I enter my virtualenv, I see this behavior:
me#ARL--M6800:~/Downloads/neon$ source .venv/bin/activate
(.venv) me#ARL--M6800:~/Downloads/neon$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pytools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pytools
>>>
>>> import sys
>>> sys.path
['', '/usr/local/lib/python2.7/dist-packages', '/home/me/Downloads/neon',
'/home/me/Downloads/neon/.venv/lib/python2.7',
'/home/me/Downloads/neon/.venv/lib/python2.7/plat-x86_64-linux-gnu',
'/home/me/Downloads/neon/.venv/lib/python2.7/lib-tk',
'/home/me/Downloads/neon/.venv/lib/python2.7/lib-old',
'/home/me/Downloads/neon/.venv/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/me/Downloads/neon/.venv/local/lib/python2.7/site-packages',
'/home/me/Downloads/neon/.venv/lib/python2.7/site-packages']
(.venv) me#ARL--M6800:~/Downloads/neon$ pip install pytools
Requirement already satisfied (use --upgrade to upgrade): pytools in
/usr/local/lib/python2.7/dist-packages/pytools-2016.1-py2.7.egg
Requirement already satisfied (use --upgrade to upgrade):
decorator>=3.2.0 in /usr/local/lib/python2.7/dist-packages (from pytools)
Requirement already satisfied (use --upgrade to upgrade): appdirs>=1.4.0
in /usr/local/lib/python2.7/dist-packages/appdirs-1.4.0-py2.7.egg (from
pytools)
Requirement already satisfied (use --upgrade to upgrade): six>=1.8.0 in
/usr/local/lib/python2.7/dist-packages (from pytools)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6.0 in
/usr/local/lib/python2.7/dist-packages (from pytools)
So, I can't import pytools becauseit isn't on my sys.path. According to pip, it is installed in the /usr/local/lib/python2.7/dist-packages/pytools-2016.1-py2.7.egg directory, which leaves me with 3 questions:
First: Why can my virtualenv see my system-wide packages? I thought the default was not to see them. When I look at the Makefile used to create the virtualenv, I see this
# where our installed python packages will live
VIRTUALENV_DIR := .venv
VIRTUALENV_EXE := virtualenv -p python2.7 # use pyvenv for python3 install
ACTIVATE := $(VIRTUALENV_DIR)/bin/activate
which should give me default behavior.
Second: Why are there egg directories in my dist-packages dir? Doesn't this make it harder to find those modules? (Though apparently, the sys.path for my system environment python has been updated to search in the egg dir. When/How???)
Third: What is an efficient way of fixing things so that my virtualenv will have access to pytools?
(I would've numbered my list instead of First/Second/Third, but then the Makefile code I inserted didn't format well)
First of all, I don't know anything about Nervana's Neon.
I get the same sys.path when the virtualenv is created with root privileges:
dm#Z580:~$ sudo virtualenv test1 -p python2.7
[sudo] password for dm:
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in test1/bin/python2.7
Also creating executable in test1/bin/python
Installing setuptools, pip, wheel...done.
dm#Z580:~$ source test1/bin/activate
(test1)dm#Z580:~$ which python
/home/dm/test1/bin/python
(test1)dm#Z580:~$ python
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> import pprint
>>> pprint.pprint(sys.path)
['',
'/home/dm/test1/lib/python2.7',
'/home/dm/test1/lib/python2.7/plat-x86_64-linux-gnu',
'/home/dm/test1/lib/python2.7/lib-tk',
'/home/dm/test1/lib/python2.7/lib-old',
'/home/dm/test1/lib/python2.7/lib-dynload',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-x86_64-linux-gnu',
'/usr/lib/python2.7/lib-tk',
'/home/dm/test1/local/lib/python2.7/site-packages',
'/home/dm/test1/lib/python2.7/site-packages']
I would remove the current virtualenv, recreate it without sudo and then install all requirements with the virtualenv's pip.
cd ~/Downloads
rm -rf neon/.venv/
virtualenv neon/.venv/ -p python2.7
source neon/.venv/bin/activate
pip install -r neon/requirements.txt
For what it's worth, I uninstalled pytools using pip in my main environment. Then, went into my virtual environment and used pip to install pytools. Finally, went back to my main environment and reinstalled pytools using pip install.
Now things are working. (Though oddly, pytools is no longer installed in a '.egg' directory. I think this is better, but am now even more puzzled as to why/when things get installed into .egg directories)

Categories

Resources