Getting error in installing rpy2 on windows - rpy2

I am trying to install rpy2 package and getting following error both with
C:\python27>easy_install rpy2
Searching for rpy2
Reading http://pypi.python.org/simple/rpy2/
Reading http://rpy.sourceforge.net
Best match: rpy2 2.3.3
Downloading http://pypi.python.org/packages/source/r/rpy2/rpy2-2.3.3.tar.gz#md5=6cd95eb70645577cb53198ef0a32395e
Processing rpy2-2.3.3.tar.gz
Running rpy2-2.3.3\setup.py -q bdist_egg --dist-dir c:\users\chetan~1\appdata\local\temp\easy_install-wfxip9\rpy2-2.3.3\egg-di
st-tmp-rrezfb
"C:\PROGRA~2\R\R-28~1.0\bin\R" CMD config --ldflags
Invalid substring
in string
C:\Python27\lib\site-packages\setuptools\command\easy_install.py:921: RuntimeWarning: tp_compare didn't return -1 or -2 for ex
ception
raise DistutilsError("Setup script exited with %s" % (v.args[0],))
error: Setup script exited with Problem while running `"C:\PROGRA~2\R\R-28~1.0\bin\R" CMD config --ldflags`
And when I try pip this is what I get
c:\Python27\Lib\site-packages\django\bin>pip install rpy2
Downloading/unpacking rpy2
Running setup.py egg_info for package rpy2
"C:\PROGRA~2\R\R-28~1.0\bin\R" CMD config --ldflags
Invalid substring
in string
Problem while running `"C:\PROGRA~2\R\R-28~1.0\bin\R" CMD config --ldflags`

I spent a few days on this too... then I stumbled upon this thread, where a link is given: http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2
On this page you can find (amongst other useful things) a pre-compiled version of rpy2 for Windows, and for different versions of Python. It apparently only works for R 2.15.3, I did not try it with other versions.

The error
"C:\PROGRA~2\R\R-28~1.0\bin\R" CMD config --ldflags
is probably caused by the absence of unix like tools in windows. (you might also have had an error like
'sh' is not recognized as an internal or external command, operable program or batch file
I finally got it to work on windows 7 by installing Rtools and mingw compiler and changing the setup.py and unixccompiler.py file. See rpy2 install on windows 7
Also the error
%load_ext rmagic
RuntimeError("Unable to locate R.dll within %s" % RHOME)
is caused by rpy2 not able to find R.dll correctly in the code. You can add R_HOME environment variable as eg C:\Program Files\R\R-3.0.2 the outside folder (for details see the link).
Hope this helps..

Recently had to attempt to build this from source. Got the rpy2-2.2.2 version so I can use with with Python 2.6.6 on Oracle Linux.
The solution to getting this to work was to fix a couple of things in the setup.py script.
First, allow get_rconfig() to allow empty strings. If there was a way to flag this, it wasn't obvious to me:
config = RConfig()
for about in ('--ldflags', '--cppflags',
'LAPACK_LIBS', 'BLAS_LIBS'):
#config += get_rconfig(r_home, about)
config += get_rconfig(r_home, about, allow_empty = True)
Secondly, fix a bug with the dropthrough in RConfig.from_string, where it was referencing a non-existent variable:
elif rconfig_m is None:
if allow_empty:
#if allow_empty and (rconfig == ''):
print(cmd + '\nreturned an empty string.\n')
This then allows the R CMD config loops to get parsed and the empty cases (which you will probably encounter if your R build was not built as a shared library) and I am able to complete the cycle with
python setup.py build install

Related

I cannot run pyinstaller on my computer even though I have installed it

This is the problem right here, do you have any advice for that?
installed pip and pyinstaller, but still got this error message when I tried to convert my project into an .exe.
From Pyinstaller installation guide:
If you cannot use the pyinstaller command due to the scripts directory not being in PATH, you can instead invoke the PyInstaller module, by running python -m PyInstaller (pay attention to the module name, which is case sensitive). This form of invocation is also useful when you have PyInstaller installed in multiple python environments, and you cannot be sure from which installation the pyinstaller command will be ran.
So you may run it as e.g.:
python -m PyInstaller some_system.py
Or, as the issue seems that PATH Windows environment variable doesn't include Python's Script folder, it'd better to fix it. From the same guide:
If the command is not found, make sure the execution path includes the proper directory:
Windows: C:\PythonXY\Scripts where XY stands for the major and minor Python version number, for example C:\Python38\Scripts for Python 3.8)
To fix you may run where python to get exact location of Python on your machine (let's say it shows C:\Python38\). Then add to PATH env variable Scripts folder inside it (in this example it'd be C:\Python38\Scripts\)

pycharm and pyinstaller confusion

I have been writing .py scripts using PyCharm in Windows 10. I want to compile them into standalone .exe so I installed pyinstaller. I believe I made a mistake by installing it via the terminal inside PyCharm instead of cmd.
Pyinstaller was initially installed in C:\Users\myuser\PycharmProjects\routine\venv\Scripts
(\routine\ is the name of the project where I keep my scripts for tasks I do on a routine basis.)
When I DIR in \Scripts, I can see pyinstaller.exe
When I run pyinstaller from \Scripts, I get the following error:
Fatal error in launcher: Unable to create process using '"c:\users\myuser\pycharmprojects\routine tasks\venv\scripts\python.exe" "C:\Users\myuser\PycharmProjects\routine\venv\Scripts\pyinstaller.exe" ': The system cannot find the file specified.
If I try to run pyinstaller from a different directory, I get this message: "'pyinstaller' is not recognized as an internal or external command, operable program or batch file."
If I try to install pyinstaller from anywhere else, I get a bunch of messages saying "Requirement already satisfied: pyinstaller in c:\users\myuser\appdata\local\packages\pythonsoftwarefoundation.python.3.7_qbz5n2kfra8p0\localcache\local-packages\python37\site-packages"
If I uninstall pyinstaller with pip and then reinstall it, I get this message "WARNING: The scripts pyi-archive_viewer.exe, pyi-bindepend.exe, pyi-grab_version.exe, pyi-makespec.exe, pyi-set_version.exe and pyinstaller.exe are installed in 'C:\Users\myuser\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\Scripts' which is not on PATH."
If I add the specified directory to PATH I still get the same message.
Any idea what I am doing wrong here, or any suggestions as to how to fix this?

PyNaCl building problems

So I'm trying to download discord's API into my venv with pip but it's failing to build PyNaCl. It says that the error is that the 'make' utility is missing from PATH but I just added it in my environment variables and tried running it on cmd to make sure it's properly installed. Any ideas on what could be causing the issue?
I'm running windows 10, python 3.9.1, and pip 20.3.3
Here is the error message:
Note: I can perfectly install the discord module without voice support, however, I want to make use of its voice features and I cannot understand why it's failing to install.
'make' utility is missing from PATH
The cause of this error
This error is caused by a BUG in setup.py of PyNacl source code.
However, even if you fix it, you will encounter more problem since that source code does not intend for building on windows.
If you just want to install PyNacl, see the next section.
If you want to know the detail of that BUG, see the last section.
Installing PyNacl
After Sep 14, 2020, pynacl has abi3 pre-built wheel, so pip install pynacl will automatically download and install it. You don't need to build pynacl by yourself.
You can also manually download
PyNaCl-1.4.0-cp35-abi3-win_amd64.whl and pip install PyNaCl-1.4.0-cp35-abi3-win_amd64.whl (in download dir).
If you get an error, you can use pip install -U pip to upgrade pip and try again.
If you still get an error, you can use pip debug -v to check compatible tags:
If the compatible tags have the "win_amd64" postfix, there should be a "cp35-abi3-win_amd64" tag, and pip install should succeed.
If the compatible tags have the "mingw_x86_64" or "mingw_x86_64_ucrt" postfix, you must build pynacl by yourself (or install win_amd64 python).
pynacl lists libsodium as a dependency. Fortunately, you don't need to build libsodium (which needs make, causing the error you encountered).
You can download pre-built libsodium from https://download.libsodium.org/libsodium/releases/.
download: https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-mingw.tar.gz
unzip .gz (you can use 7-zip or peazip) and copy the directories ("bin", "lib", "include") in /libsodium-1.0.18-stable-mingw.tar/libsodium-win64 to your mingw installation directory(which also contain "bin", "lib", "include")
finally, use bash (such as git bash): SODIUM_INSTALL=system pip install pynacl.
Then pip will use PEP517 to build and install pynacl for you with pre-built libsodium. Or, you can build by yourself (download the source code from pypi, and in the source code directory):
SODIUM_INSTALL=system python setup.py bdist_wheel
With cmd or powershell, you cannot set environment variable in the bash style. You can use following instead:
$env:SODIUM_INSTALL="system";pip install pynacl
Details of the bug
The error is raised here:
if not which("make"):
raise Exception("ERROR: The 'make' utility is missing from PATH")
And the function which is implemented with a BUG:
def which(name, flags=os.X_OK): # Taken from twisted
result = []
exts = filter(None, os.environ.get('PATHEXT', '').split(os.pathsep))
path = os.environ.get('PATH', None)
if path is None:
return []
for p in os.environ.get('PATH', '').split(os.pathsep):
p = os.path.join(p, name)
if os.access(p, flags):
result.append(p)
for e in exts:
pext = p + e
if os.access(pext, flags):
result.append(pext)
return result
In Python3, filter returns an iterator, not a list (python2's filter returns a list). Thus, the "exts" will be "exhausted" in the first iteration. You can replace filter(...) with list(filter(...)) to fix it.

How to install miniupnpc as a python module on windows

I want to use UPnP in my python scripts, so I tried to install miniupnpc through pip install miniupnpc. But It causes an error a little bit after the installation starts:
ERROR: Command errored out with exit status 1:
cwd: C:\Users\sammy\AppData\Local\Temp\pip-install-jrjs0fss\miniupnpc\
Complete output (4 lines):
running install
running build
running build_ext
error: [WinError 2] The system cannot find the file specified
----------------------------------------
I checked the GitHub but I don't know where to find the tools I need to compile the python module or how to use them.
I believe at the time the library was a little bit bugged, I never worked out the issue in the end, I recommend looking for other tools.
It is also worth mentioning I wasn't a very good programmer back then, I now actually understand the nature of libraries and packages.

'python3' is not recognized as an internal or external command, operable program or batch file

I am using Python 3.5.2 version on Windows 7 and tried using python3 app.py. I am getting this error message:
'python3' is not recognized as an internal or external command,
operable program or batch file.
Is there any specific cause about why the python3 command is not working?
I also verified that the PATH is added to environment variables.
There is no python3.exe file, that is why it fails.
Try:
py
instead.
py is just a launcher for python.exe. If you have more than one python versions installed on your machine (2.x, 3.x) you can specify what version of python to launch by
py -2 or
py -3
You can also try this:
Go to the path where Python is installed in your system. For me it was something like C:\Users\\Local Settings\Application Data\Programs\Python\Python37
In this folder, you'll find a python executable. Just create a duplicate and rename it to python3. Works every time.
Python3.exe is not defined in windows
Specify the path for required version of python when you need to used it by creating virtual environment for your project
Python 3
virtualenv --python=C:\PATH_TO_PYTHON\python.exe environment
Python2
virtualenv --python=C:\PATH_TO_PYTHON\python.exe environment
then activate the environment using
.\environment\Scripts\activate.ps1
Yes, I think for Windows users you need to change all the python3 calls to python to solve your original error. This change will run the Python version set in your current environment. If you need to keep this call as it is (aka python3) because you are working in cross-platform or for any other reason, then a work around is to create a soft link. To create it, go to the folder that contains the Python executable and create the link. For example, this worked in my case in Windows 10 using mklink:
cd C:\Python3
mklink python3.exe python.exe
Use a (soft) symbolic link in Linux:
cd /usr/bin/python3
ln -s python.exe python3.exe
In my case I have a git hook on commit, specified by admin. So it was not very convenient for me to change the script (with python3 calls).
And the simplest workaround was just to copy python.exe to python3.exe.
Now I could launch both python and python3.
If python2 is not installed on your computer, you can try with just python instead of python3
For Python 27
virtualenv -p C:\Python27\python.exe django_concurrent_env
For Pyton36
virtualenv -p C:\Python36\python.exe django_concurrent_env
Enter the command to start up the server in that directory:
py -3.7 -m http.server
I had a related issue after installing windows 11, where python3 in cmd would open the windows store. I was able to sort it out between this post and this other one. In short, I reinstalled python and made sure to add it to PATH. Then, in settings, Apps > Apps & Features > App Execution aliases. Here, all I had to do was make sure that every single python .exe (including idle and pip) were turned off EXCEPT FOR the python3.exe alias. Now it works like a charm.
FWIW:
The root of this issue is not with you or with python. Apparently, Microsoft wanted to make installing python easier for young kiddos getting interested in coding, so they automatically add an executable to PATH. For those of us that already have this executable, it can cause these issues.
Found out instead press the play button the top right and it should work in visual studios:
Do not disable according to first answer
Saying python3 in the command will not work by default.
After figuring out the problem with the modules (Solution): https://youtu.be/paRXeLurjE4
Summary:
To import python modules in case of problem to import modules:
Hover over python in search:
Click open in folder
Hover over and right click
click properties
copy everything in path before \python.exe
close those windows
For cmd (administrator):
cd --path that was copied--
then python -m pip install --upgrade pip
cd Scripts
pip install "Name of Package" such as pip install --module (package) --
Im on win10 and have 3.7, 3.8 and 3.10 installed.
For me "python" launches version 3.10 and does not accept commands (like -3.7), "py" launches newest version but does accept commands, and "python3" does nothing.
Uninstalled 3.10 and "python" now does nothing, and "py" launches 3.8.
I am unable to add a comment, but the mlink option presented in this answer above https://stackoverflow.com/a/55229666/8441472 by #Stanislav preserves cross-platform shebangs at the top of scripts (#!/usr/bin/env python3) and launches the right python.
(Even if you install python from python.org, Windows will direct you to the app marketplace nowadays if you type python3 on the command line. If you type python on the same cli it will launch the python.org version repl. It leads to scripts that generate no output, but more likely silently failed completely. I don't know ho common this is but have experienced it on a couple of different devices)
If you have this at the top of your script to ensure you launch python3 and don't feel like editing everything you own, it is not a bad approach at all... lol.

Resources