Why does IronPython tell me that pip is a package and not an executable? - pip

I am a complete newbie at Python. I wanted to try to see if Pyomo (a Python package for mathematical modeling) could work under IronPython because all my code for generating the data needed for Pyomo is in C#.
I installed IronPython 2.7.5, then tried as an administrator the advice found in http://blog.ironpython.net/2014/12/pip-in-ironpython-275.html#disqus_thread on how to run "pip" for IronPython. I used the exact example they gave (installing html5lib):
ipy -X:Frames -m ensure pip
ipy -X:Frames -m pip install html5lib
The first line worked, and I see in the Lib/site-packages directory a folder called pip-6.1.1-py2.7.egg with lots of python code in it.
For the second line, I received the error:
Unhandled exception:
Traceback (most recent call last):
File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 170, in run_module
File "C:\Program Files (x86)\IronPython 2.7\Lib\runpy.py", line 111, in _get_module_details
ImportError: No module named urllib; 'pip' is a package and cannot be directly executed
At this point, I'm stuck. Any help would be appreciated.
Just in case this helps, printing out the sys.version gives:
2.7.5 (IronPython 2.7.5 (2.7.5.0) on .NET 4.0.30319.34209 (32-bit))

I encountered the same problem. It seems that IronPython can't deal with more recent versions of pip. What I did was:
remove all traces from pip and setuptools from IronPython's Lib\site-packages folder
run from a commandline: ipy.exe -X:Frames -m ensurepip
this installed an old version of pip, one that IronPython understands. Verify this by checking that a folder pip-1.5.6.dist-info appears in IronPython's Lib/site-packages
Moral of the story; don't upgrade to a newer pip version when using IronPython

Related

Python 3.9 import issue

I just installed Python 3.9 with the Windows 64-bit installer. For some reason the all of the modules I had previously installed using pip will no longer import, unless I am running Python from the directory where they are located: C:\Users\<user>\AppData\Local\Programs\Python\Python38-32\Lib\site-packages
I tried uninstalling/reinstalling the requests module with pip and then importing requests in a shell, still not recognized.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'requests'
I imagine this is probably some environmental variable path issue. I'm new to Python, any help getting this straightened out much appreciated.
Each version of python has its own global sites package directory where it stores the packages you install.
Ex: Python 3.8 will store under %appdata%\Local\Programs\Python\Python38-32\Lib\site-packages
Python 3.9 would store it in a different location (like Python39-32)
In order to install a package for specific version of python you need to install it with python version command.
py -3.9 -m pip install requests
You can refer the official documentation here

Using pip 10.0.1 to install modules

lately using 9.0.1, I have been using Project Interpreter to import modules for my files. I opened up a new project in PyCharm today to try and test 10.0.1. Using the Pip version of 10.0.1, I couldn't install packages into my file.
The command output was :
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\packaging_tool.py", line 192, in main
retcode = do_install(pkgs)
File "C:\Program Files\JetBrains\PyCharm Community Edition 2017.3.3\helpers\packaging_tool.py", line 109, in do_install
return pip.main(['install'] + pkgs)
AttributeError: module 'pip' has no attribute 'main'
I googled this and it said that installing modules through pip was now unsupported, especially for
pip._internal.main
After looking at this site : https://pip.pypa.io/en/latest/user_guide/#using-pip-from-your-program for a while, it says to use :
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'my_package'])
I tried executing it and command prompt said that subprocess.check_call is not an internal or external file.
i also tried executing the commands through Command Prompt and downgrading my pip to 9.0.1 but none of this worked. When I changed Pip to 9.0.1 in Command Prompt, it had no effect on PyCharm.
Can anyone help with trying to import modules into PyCharm because I am currently trying to make a webcrawler using modules beautifulsoup4 and it is not letting me import it.

Scipy installation windows 10

I have some difficulties trying to install Scipy for Python 3.5 on a Windows 10 machine and I hope I can find some help here. So here is what I have done so far.
I have downloaded the numpy+mkl for python 3.5 and 64bit version as well as the scipy0.18.1 for the same versions, from Gohlke's website
I installed the numpy+mkl whl with:
python -m pip install numpy-1.11.2+mkl-cp35-cp35m-win_amd64.whl
all goes well.
then I install the scipy package the same way like:
python -m pip install scipy-0.18.1-cp35-cp35m-win_amd64.whl
This also completes.
However, when I try to run python afterwards I get the following error:
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
File "C:\Python35\Lib\site-packages\scipy\io\__init__.py" , line 97, in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\__init__.py", line 13 in <module>
File "C:\Python35\Lib\site-packages\scipy\io\matlab\mio.py", line 8 in <module>
ImportError: No module named 'numpy'
I also get a pop-up that Python has stopped working.
I have tried a different order in which I installed the packages, but all lead to the error mentioned when Scipy is installed.
I also installed did this on a windows 7 machine and there it works.
Does anybody have any idea what causes this issue?
I also had some issues. So I just installed Anaconda3 insted of python directly.

HTTPLIB2 Error installing python-twitter on mac osx

Hello I am trying to install python-twitter and one of the dependencies HTTPLIB2 is giving me a lot of problems. I have searched the internet up and down but maybe I do not know what the right key words are. Here is the problem.
I am installing python-twitter. I install the requirements either by "pip install -r requirements.txt" or doing them one by one through for example "pip install httplib2". Then I run "python setup.py install". It's happy but then "python setup.py test" fails as followed with an error on import HTTPLIB2.
python setup.py test
running test
running egg_info
writing requirements to python_twitter.egg-info/requires.txt
writing python_twitter.egg-info/PKG-INFO
writing top-level names to python_twitter.egg-info/top_level.txt
writing dependency_links to python_twitter.egg-info/dependency_links.txt
reading manifest file 'python_twitter.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching '.DS_Store'
writing manifest file 'python_twitter.egg-info/SOURCES.txt'
running build_ext
Traceback (most recent call last):
File "setup.py", line 73, in <module>
Main()
File "setup.py", line 66, in Main
setuptools.setup(**METADATA)
File
....
<deleted these parts to save space>
module = __import__('.'.join(parts_copy))
File "/Users/ME/Downloads/python-twitter-1.0/twitter_test.py", line 30, in <module>
import twitter
File "/Users/ME/Downloads/python-twitter-1.0/twitter.py", line 65, in <module>
import oauth2 as oauth
File "/usr/local/lib/python2.7/site-packages/oauth2/__init__.py", line 32, in <module>
import httplib2
File "/usr/local/lib/python2.7/site-packages/httplib2/__init__.py", line 347
print('%s:' % h, end=' ', file=self._fp)
^
SyntaxError: invalid syntax
But I thought the print error was an incompatibility between python 2 and 3. Why am I getting this while I clearly have python 2.7 (I checked and uninstalled and reinstalled HTTPLIB2).
Thanks much for your help
i had a same issue. It seems to be python2.7 and 3.x version conflict issue and resolved by
python2.7 -m pip install -t lib/ -r requirements.txt
Just in case, this happens when you install httplib2 with a python3 version of pip and then execute it with python2.
This happens for example when creating manually an environment with:
pip install -t lib/ -r requirements
As it happens when creating an AppEngine standard environment vendor folder.
This happens because contrary to most of the libraries, httplib2 has completely different versions for python2 and python3.

TypeError when downloading rapidsms using pip in django-tables2

I'm a total python newbie. I installed python 3.3.1 on a 32 bit windows 7 professional. I'm trying to install RapidSMS, and it should be as easy as "pip install rapidsms" and it does start the process, but it doesn't complete and I'm left with the below error message.
I've been trying to google it, but I haven't been able to find this specific problem, for the error I find fixes for people who have written the code themselves, and I haven't seen anyone mention this problem about rapidsms themselves. Since it stops in Django-tables, I wonder if I messed up that installation somehow or if there's a problem with the python version compatibility. I've used pip when installing some other software, so I don't think that's the problem.
So if anyone's encountered this error when installing pyhton packages or really have any idea what the cause might be I'd really appreciate it! (I also plan to post this in the RapidSMS mailing list when I get approved, but wanted to see if this was a more general problem that might have a fix.)
Downloading/unpacking django-tables2==0.13.0 (from rapidsms)
Running setup.py egg_info for package django-tables2
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\mhealth1\appdata\local\temp\pip-build-mhealth1\django-tables2\setup.py", line 7, in <module>
version = re.search('__version__ = "(.+?)"', f.read()).group(1)
File "C:\Python33\lib\re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "c:\users\mhealth1\appdata\local\temp\pip-build-mhealth1\django-tables2\setup.py", line 7, in <module>
version = re.search('__version__ = "(.+?)"', f.read()).group(1)
File "C:\Python33\lib\re.py", line 161, in search
return _compile(pattern, flags).search(string)
TypeError: can't use a string pattern on a bytes-like object
----------------------------------------
Command python setup.py egg_info failed with error code 1 in c:\users\mhealth1\a
ppdata\local\temp\pip-build-mhealth1\django-tables2
Storing complete log in C:\Users\mhealth1\pip\pip.log
Django-tables2 fails to install in Python3 because of the following code from line 7 of setup.py in the traceback:
version = re.search('__version__ = "(.+?)"', f.read()).group(1)
This should work if the search pattern was a bytes object. A byte literal can be created by simply pre-pending the string literal with a b like the following:
version = re.search(b'__version__ = "(.+?)"', f.read()).group(1)
This is why Python is throwing a TypeError with the message "Can't use a string pattern on a bytes-like object". The file contents are being read in as bytes.
I don't think RapidSMS currently supports Python3 yet based on its list of environments that are tested. This can be seen in the tox environments list of the project seen here, in which only Python 2.6 and 2.7 are listed: https://github.com/rapidsms/rapidsms/blob/develop/tox.ini#L2
To solve the immediate problem, you'll want to install RapidSMS in a virtual environment with Python 2.6 or 2.7. The documentation for RapidSMS describes virtual environment setup briefly here: http://www.rapidsms.org/en/develop/topics/virtualenv.html
You'll want to install Python 2.6 or 2.7 on your system and specify which Python for the virtualenv to use, using the -p or --python argument. The following is taken from the RapidSMS docs linked above, but ammended to specify using Python 2.7:
mkvirtualenv --distribute --no-site-packages rapidsms --python=python2.7

Resources