Environment variables and RStudio - rstudio

I'm using RStudio and have been trying to use the rPython package to do some email handling for me. This involves unpacking some email attachments so I need to use a newer version of Python than 2.7.
I am on ubuntu so I've set environment variables in a bash script which I can see has worked:
bash
alias python=python3
export RPYTHON_PYTHON_VERSION=3
command line
echo $RPYTHON_PYTHON_VERSION
3
And yet, when I install rPython in RStudio it says:
Installing package into ‘/home/richardc/R/x86_64-pc-linux-gnu-library/3.1’
(as ‘lib’ is unspecified)
trying URL 'http://cran.rstudio.com/src/contrib/rPython_0.0-5.tar.gz'
Content type 'application/x-gzip' length 37109 bytes (36 Kb)
opened URL
downloaded 36 Kb
installing source package ‘rPython’ ...
** package ‘rPython’ successfully unpacked and MD5 sums checked
a specific python version to use was not provided
defaulting to the standard python in the system
So, despite python --version returning 3.4 and setting the environment variable it is defaulting to 2.7
I'm hoping that there is something straightforward I'm missing.

#nickbloom was actually close to it, but it is not Sys.setenv(RPYTHON_PYTHON_PATH=3) but Sys.setenv(RPYTHON_PYTHON_VERSION=3)
In my case (I have Python 3.5) it was:
> Sys.setenv(RPYTHON_PYTHON_VERSION=3.5)
> install.packages('rPython')
Installing package into ‘/usr/lib64/R/library’ (as ‘lib’ is unspecified) trying URL
'http://r.meteo.uni.wroc.pl/src/contrib/rPython_0.0-5.tar.gz' Content
type 'application/x-gzip' length 37109 bytes (36 KB)
================================================== downloaded 36 KB
* installing *source* package ‘rPython’ ...
** package ‘rPython’ successfully unpacked and MD5 sums checked which: no python3.5-config in (/sbin:/bin:/usr/sbin:/usr/bin) could not
locate python3.5-config
As you can see now it is looking for python3.5-config, which is the version I specified above.
Also if your python3.5-config file is not in the PATH then you might also want to set the PATH:
Sys.setenv(PATH='/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin')
You might also need to rename python3.5m-config, because rPython always looks for [pythoncommand]-config, which in my case was python3.5 and not python3.5m, so I just renamed python3.5m-config to python3.5-config and then the rPython package has installed.

I know this is way late, but I believe you have to set the R environment variable, not the bash environment variable. Set it like this: Sys.setenv(RPYTHON_PYTHON_PATH=3)
HTH.
EDIT: Nope, that's not it. I'm stumped, too.

In my case, none of the provided answers worked. I suspect it's because I installed python3 through homebrew (I'm on Mac OSX).
However, this worked:
I edited the configure.ac file in the downloaded package and then installed it through R CMD INSTALL.
MYPYTHONCONFIG=python3-config
MYPYTHON=python3

Related

ldf is not supported

I install asammdf package to read dat file in python. After installing asammdf using pip install asammdf, the installation is successful. However, when I import asammdf, I got ldf is not supported.
May I know how to solve this issue and after installing the asammdf? Moreover I also cannot open the spyder in my anaconda
That is just a warning message from the canmatrix library. If you don't use LIN database file (ldf files) for bus logging decoding then you can just ignore it.
If you really want to make it go away then just install the ldfparser package since this is required for ldf support ( see
https://github.com/ebroecker/canmatrix/blob/6ed291b73a5824e367615c99ee1b4e6084eb026e/setup.py#L98)

PyMesh problems with Setup on Windows10 and Error using Docker Version

I want to install PyMesh on a Windows 10 PC, if possible it should be installed in the side-packages of an interpreter delivered with the IDE we use.
I tried the way to run the setup discribed here
https://pymesh.readthedocs.io/en/latest/installation.html
so the part :
git clone https://github.com/PyMesh/PyMesh.git
cd PyMesh
git submodule update --init
worked without any problems.
I am not sure on windows if I now just can write
set PYMESH_PATH = path
and if i can use the path "...\PyMesh\PyMesh" here?
so i left out this part
I installed numpy and scipy (allready installed)
and nose because it is mentioned in the requirements.txt.
So my numpy scipy and nose versions are
numpy 1.19.1
scipy 1.6.0
nose 1.3.7 (same as requirenments)
and just run the setup.py with admin rights
python .\setup.py install
which also seemed to work but i got an error trying
python -c "import pymesh; pymesh.test()"
from the PyMesh folder
saying ModuleNotFoundError: No module named 'PyMesh'
or if i go up one Folder doing the same
saying AttributeError: module 'PyMesh' has no attribute 'triangle'
I found this link ImportError: No module named PyMesh
but i just dont know what i should type in there
I tried to install via pip by using pip install pymesh
but pip Installer gives me a different library.
So i tried in the docker version and in docker i tried the pymesh.load_mesh method with an stl File
but got
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
I dont know if this is just the stl format (expecting binary getting ascii or vice versa)
The stl file itself can be opened so shouldnt be corrupted.
So is there a different way to install pymesh? A wheel would be great. Is it possible to install pymesh to the side-packages of a given Interpreter? Did someone else allready had the same error in Docker and knows the issue
thank you for your help

kmpfit module not in Kapteyn v2.2 module list

I am using Python 2.7 through Anaconda 2.7.8 and need Kapteyn 2.2 to perform Non-linear Least Squares fitting easily (it is probably an alternative to Scipy.optimize.leastsq() for dummies like me!).
After copy-pasting this from a previous post here on Stack Overflow:
conda install -c https://conda.binstar.org/dhirschfeld pyodbc
and then running on my cmd (as I did not have pyodbc installed I think, because of which maybe the command prompt on my Windows 7 64-bit system was not responding well to python setup.py install inside the Anaconda directory where I unzipped the Kapteyn .zip file downloaded from University of Groningen website.
But, after the installing pyodbc properly and running python setup.py install, the cmd gave me an error saying error: command 'C:\Users\windows 7\Anaconda\Scripts\gcc.bat' failed with exit status 1. Later, when I tried to import kmpfit module (needed for Non-linear least square fitting with Kapteyn), here is the problem:
import kapteyn
help(kapteyn)
Help on package kapteyn:
NAME
kapteyn - Kapteyn package.
FILE
c:\users\windows 7\anaconda\kapteyn\__init__.py
PACKAGE CONTENTS
_ni_support
celestial
doccer
filters
interpolation
maputils
mplutil
positions
rulers
shapes
tabarray
wcsgrat
DATA
__all__ = ['celestial', 'wcs', 'wcsgrat', 'tabarray', 'maputils', 'mpl...
__version__ = '2.2'
VERSION
2.2
As you can see, there is no module named kmpfit (or even wcs) here. But according to http://www.astro.rug.nl/software/kapteyn/intro.html, these two should be there.
Kindly help. I have never imported any module before.
Thanks in advance...:-)
I just managed to get this working (on Mac OSX, so you may have to adjust this). My steps were:
$ conda install pyodbc (didn't need to go through binstar)
Download & unarchive the kapteyn package, then navigate to its directory
$ python setup.py install, which used my OS's C compiler and Anaconda's python, and installed kapteyn to my anaconda distro's site-packages, as it should.
Check that kmpfit.so is in the kapteyn folder in site-packages, showing that kmpfit installed correctly.
>> from kapteyn import kmpfit failed, ImportError: cannot import name kmpfit. I did some digging and discovered that it was still importing kapteyn from the folder that I downloaded, not from site-packages.
Delete the downloaded kapteyn folder, then try again. It worked!

Python - cant find pip.ini or pip.conf in Windows

I got Python 2.7.8 installed on my Win7 machine, which comes with pip already pre-installed. I'm successfully able to install new packages from pip and now I need to add custom repository url to the install list of pip
To do so I need to modify pip.ini which is in %APPDATA%\pip\pip.ini according to the Official Manual
However there are no pip folder anywhere (not in Roaming, not in Local, not in LocalLow)
nor there exists PyPa folder in: C:\ProgramData\PyPA\pip\pip.conf
Could you tell me where do i search for pip.ini? how to add foreign repo to the install list?
Instead of checking a list of well-known locations, you can ask pip to list the valid locations:
pip config -v list
Fun fact
On the same machine, with the same pip version, the valid locations can vary based on the actual Python version.
Environment: Win 7 x64, the HOME environment variable is set to D:\Home
Python 3.7.3:
> pip config -v list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'D:\Home\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'C:\Python37\pip.ini'
Python 3.8.0:
> pip config -v list
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\foobar\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'C:\Python38\pip.ini'
Finally got it sorted.
Apparently for Windows users pip.ini config file is not created, however can be added manually!
just create new %APPDATA%\pip\pip.ini and content of custom repository:
[install]
find-links = https://<login>:<password>#your.repo.com/custom/url
Reference: https://pip.pypa.io/en/stable/user_guide/#config-file
A bit late, but for reference:
Try adding the pip.ini file in %USERPROFILE%\pip\pip.ini (usually: C:\Users\<username>\pip\pip.ini).
On windows pip.exe looks for "pip.ini" in this order:
C:\ProgramData\pip\pip.ini
C:\Users\<username>\pip\pip.ini
C:\Users\<username>\AppData\Roaming\pip\pip.ini
It's been 7 years, and I think there's now a better answer for most people -- but it does depend on version of pip. For the most recent pips I'm using:
$ pip config -v debug
lists where it's looking and you can decide which location is
most useful for what you've got in mind. It does look like a fairly recent
change: On a year-old docker image I had with pip 20.1
I got "ERROR: Need an action (edit, get, list, set, unset) to
perform." On that system, pip config -v list gave a list of files it would try, this is supposed to be 'global', 'user' or 'site' variants of pip.ini locations.
For Windows 10, for pip 21.2.4 on both 3.9.6 and 3.6.8, I get response below with pip config -v debug, while pip config -v list is silent (unless a pip.ini is found).
global:
C:\ProgramData\pip\pip.ini, exists: False
site:
c:\py\myvenv\pip.ini, exists: False
user:
C:\Users\myname\pip\pip.ini, exists: False
C:\Users\myname\AppData\Roaming\pip\pip.ini, exists: False
From a downloaded image I got from dockerhub in June 2021 with pip 21.2.2 and python 3.6.10:
pip config -v debug
env_var:
env:
global:
/etc/xdg/pip/pip.conf, exists: False
/etc/pip.conf, exists: True
global.extra-index-url: http://trynexs:8081/repository/repo_group/simple
site:
/usr/local/pip.conf, exists: False
user:
/home/tanhauser/.pip/pip.conf, exists: False
/home/tanhauser/.config/pip/pip.conf, exists: False
Pip changed the location of the config file in windows starting in pip 6.0 the pip config docs explain the location of the config files as follows.
pip --version >= 6 (as of version 18.1 hasn't changed again yet)
%APPDATA%\pip\pip.ini
pip --version < 6
%HOME%\pip\pip.ini
Inside a virtual env
%VIRTUAL_ENV%\pip.ini
Site-wide win7+ (same as of win10)
C:\ProgramData\pip\pip.ini
Site-wide winxp (note windows vista side wide not supported)
C:\Documents and Settings\All Users\Application Data\pip\pip.ini
NOTE: If multiple configuration files are found by pip then they are combined in the following order:
The site-wide file is read
The per-user file is read
The virtualenv-specific file is read
Also pip added a config command starting in pip 10.
pip config --help
I know this is a bit late, however, this post is high on the rankings when searching. Inside a virtual environment pip.ini can also be in the root of the virtual environment. From the docs and https://pip.pypa.io/en/stable/user_guide/?highlight=pip.ini#configuration
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
All the answers are partially wrong and right.
It depends on how your system is configured. The only way (for me) to find out was to patch site-packages/pip/locations.py at the point where site_config_files is assigned (around line 120 for pip 9.0.1)
print('########## ' + str(site_config_files))
and then run pip search foo
On my system it printed ########## ['C:\\ProgramData\\pip\\pip.ini'], of which location I assumed I could not create/edit. But it just worked.
Btw, for my system %APPDATA% points to C:\Users\MYUSER\AppData\Roaming, which is not looked at when running pip on my system.
Rather than guessing first check if you have any default global/local config which is read by pip with the below command:
pip config list
This will give all details of the default config loaded by python.
If the above command doesn't give any output please try to find where pip tries to find for the global config file with the below command:
pip config --editor <path to editor of your choice> edit
The above command will open the config file which pip reads by default or else it will give an error saying that the file doesn't exist.
If there's an error please go ahead and create the exact directory and file structure as show in the error. Once the file has been created please make your changes e.g.
[global]
cert = /path/to/base64/ssl/certificate.pem
proxy = http://username:password#ipaddress:port
Save the file and please try to check (the above mentioned check command) if the configs are loaded by pip or not.
For more info please follow pip config documentation
Make sure you acually have a pip.ini file, not pip.ini.txt.
For me (Windows 8, pip 9.0.1, python 3.5.3), the correct path was
c:\Users\<UserName>\.pypirc <- sic!, even on windows
Windows 10:
I had to create 'pip' directory inside
C:\Users\UserName\AppData\Roaming\
then create pip.ini file inside that 'pip' directory:
C:\Users\<username>\AppData\Roaming\pip\pip.ini
No other location worked for me.
For Windows, python will load the config from path below. So, if pip.ini file is not exist in these paths you can create the new file by refer these path depend on environment scopes (global, user & site) that you need python execute.
For variant 'global', will try loading 'C:\ProgramData\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\MyName\pip\pip.ini'
For variant 'user', will try loading 'C:\Users\MyName\AppData\Roaming\pip\pip.ini'
For variant 'site', will try loading 'c:\python39-32\pip.ini'
By the way, you can check the paths as above by
pip config -v list
On a Windows 10 machine with multiple users I used this:
c:\users\all users\pip\pip.ini
Using pip version 22.3.1 with python version 3.10.4..

easy_install M2Crypto failing on Windows platform

I am attempting to install M2Crypto on a Windows XP platform. I have Python, easy_install and SWIG installed, but when I attempt to easy_install M2Crypto I get the following:
SWIG\_m2crypto.i(31) : Error: Unable to find 'openssl\opensslv.h'
SWIG\_m2crypto.i(45) : Error: Unable to find 'openssl\safestack.h'
SWIG\_evp.i(12) : Error: Unable to find 'openssl\opensslconf.h'
SWIG\_ec.i(7) : Error: Unable to find 'openssl\opensslconf.h'
error: Setup script exited with error: command 'swig.exe' failed with exit status 1
I have read elsewhere that people have suggested easy_install openssl-devel, but that simply tells me that there are no packages found with that name. Is the name perhaps case-sensitive (I've tried various permutations without success), or does that advice not apply to Windows?
I'm not looking for alternatives to M2Crypto. I am picking up some existing code that uses it, so I need to get my development environment to be able to run what's already written.
As jay stated in his answer you should try to build it from source. And I tried. The setup.py does not recognize the --openssl option. Looking at the output from the default setup.py I realized that the search location was c:\pkg and not c:\pkg\openssl.
The solution:
Download and install OpenSSL from Win32 OpenSSL
Copy the lib and include folders to c:\pkg
Check that swig.exe is available in your path
Run easy_install M2Crypto
Worked for me like a charm.
Had a similar problem. After downloading the source package of M2Crypto and reading the INSTALL file I found the following:
Differences when installing on Windows
--------------------------------------
Before building from source, you need to install OpenSSL's include files,
import libraries and DLLs. By default setup.py assumes that OpenSSL include
files are in ``c:\pkg\openssl\include``, and the import libraries
in ``c:\pkg\openssl\lib``. As with other platforms, you can specify a different
OpenSSL location with --openssl option to build_ext command.

Resources