How to set a windows env variable from cygwin .bashrc? - python-3.x

Background: I am trying to run a windows-installed version of python from within cygwin, rather than the cygwin version (some packages I am using prefer the non-cygwin version). The following post got me up and running: Using Windows Python from Cygwin. However, I am now having an issue.
Problem: The PYTHONPATH variable does not seem to be working for me. I try "import module1" when I am using python in an arbitrary directory. module1 is located here: c:\cygwin\home\mcsefl\testFolder\module1.py. And my PYTHONPATH variable is set in my .bashrc file in the following way: "export PYTHONPATH=$PYTHONPATH:/home/mcsefl/testFolder". However I still get a "No module named..." error.
Alternate tries: Since I am running the Windows Python, I thought perhaps python did not care about the cygwin environment variables (not sure if this is true..?) So, I also tried to set the windows PYTHONPATH env variable in the control panel of windows with no luck as well.
Thanks in advance

I deleted the line in my .bashrc file that tried to set the PYTHONPATH variable and just let it be set by Windows. This corrects the problem.
Side note: The title for this Question is a misnomer now that I re-read it. My issue was resolved without addressing that overall question

Related

Mujoco_py missing path to LD_LIBRARY_PATH, Ubuntu 16.04

I am trying to get mujoco_py running. When I do
import mujoco_py
I get this error:
Exception:
Missing path to your environment variable.
Current values LD_LIBRARY_PATH=
Please add following line to .bashrc:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/jonah/.mujoco/mjpro150/bin
I have added the above line to both /etc/skel/.bashrc and ~/.bashrc. If I run
echo $LD_LIBRARY_PATH
I get
/home/jonah/.mujoco/mjpro150/bin/
My .mujoco folder includes mjkey.txt and the mjpro150 folder. I can run ./simulate successfully, so I have a feeling that this is some kind of mujoco_py specific bug.
Which program do you use to import mujoco?
I had a similar issue using mujoco_py with PyCharm Community 2018.1. A workaround was to launch PyCharm from the terminal instead of using the launcher icon. Maybe it could help with your issue too.
Otherwise you could try adding the LD_LIBRARY_PATH to ~/.profile instead of ~/.bashrc, as proposed in this answer here: https://askubuntu.com/questions/1022836/python-not-recognizing-ld-library-path/1022913#1022913
You can try to reinstall Pycharm for the newest version.
After you save the .bashrc file your want execute this code.
source ~/.bashrc
Now link is updated.
Please check the user which you run the code with. The mismatch user will cause this problem. There is the checklist may help you:
Don’t use ‘sudo’ to run the code;
Don’t use ‘sudo’ or virtual environment (e.g., anaconda) to run Pycharm (If you run the code in Pycharm).

Pycharm tensorflow ImportError but works fine with Terminal

I made a virtualenv with tensorflow installed and I changed Python interpreter set to the location where the virtualenv is located at. When I ran the program, it gives the error:
ImportError: libcudnn.so.5: cannot open shared object file: No such file or directory
I have the following lines written in my .bashrc file
export CUDA_HOME=/usr/local/cuda-8.0
export LD_LIBRARY_PATH=${CUDA_HOME}/lib64:$LD_LIBRARY_PATH
export PATH=${CUDA_HOME}/bin:${PATH}
Also, I found the libcudnn.so.5 file in the following path:
/usr/local/cuda-8.0/lib64
I encountered this error before I opened PyCharm and I did manage to install the correct cudnn version. The problem is, I can use
$ source [virtualenv_path]
to active the virtualenv and run python in terminal and everything works fine, no errors shown. The program also runs without error in Pycharm's terminal but it just gives me the above error whenever I click the run button. Could there still be something wrong with the environment variable? How do I fix it?
Unfortunately in pycharm you have to set CUDA_HOME and LD_LIBRARY_PATH inside the IDE. To do that go to the Run menu->edit configurations then choose your project. Then you click on the Environment Variables and add an entry for CUDA_HOME and LD_LIBRARY_PATH. When you have done that you can run directly from inside pycharm. I would also recommend setting the defaults to have these paths as well, so you don't have to do this for every project. Also it wouldn't hurt to make sure you have the interpreter from source [virtualenv_path] set while you are on this setting page. Let me know if you have trouble finding where to do this.
I've read this other Stackoverflow post: Pycharm environment different than command line, and it seems that the problem is that openning PyCharm in the normal way won't preserve the bash environment. The solution is to open PyCharm from the command line and everything works now. All you need to do is to open PyCharm using charm and everything works fine now.
I have searched a lot, but I didn't find the right solution for this question anywhere. I found the solution with my friends and I would like to share with you also.
If your Tensorflow works in terminal properly but doesn't work in Pycharm you have two solutions:
1- Open Pycharm from Terminal. For me:
pycharm-community
2- If you are using Unity, you need to edit .profile, because Pycharm doesn't preserve .bashrc: So, open a terminal and type:
gedit .profile
Then, add the following codes at the end of the opened file:
export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH
Save and exit. Now, you can work with Tensorflow in Pycharm without the necessity of opening the Pycharm form terminal.

Pycharm and Python Paths on Windows with Conda

I am working with multiple versions of Python, so I don't want to put any one of them in my windows path. I discovered that I can create a virtualenv (under Settings -> Project: X -> Project Interpreter and that will allow me to specify which python exe to use, but also where to get other useful programs, like pip. The end result is that using Virtualenv I can type "pip" or "python" in the terminal in Pycharm and use it as a regular terminal.
But now I'm working with Anaconda so I don't want to use virtualenv and I want to use conda instead. This works fine, but it doesn't seem to put anything into the path. (This is particularly important because where I intend to keep my project is not near my path to the python environment conda created.)
So if I type "pip" or "python" in the pycharm terminal, it doesn't recognize them. I have to specify a huge path to get it to work right.
I've been googling around and trying to find a solution to this problem. I've found a number of supposed solutions, but so far none have worked.
So, for example, I've already tried Add Content Root under project structure. This does nothing. I've tried add local, which seems to just screw everything up. (Presumably this is a way to create a local environment that I shouldn't be touching in conda.) I've tried adding a PathConfig.pth file. So far nothing works.
Remember, I don't want to add anything into the windows path (which obviously would solve my problem) because then it won't know which specific environment I want at the moment.

Windows 7: What PATH to set to when using Conda

I've got anaconda installed and was able to create a Python 3.3 environment. I can switch to it and conda info -e shows that I've switched.
However, I'm confused about what to set my PATH variable to. If I hard code it to the exact env then it works, but I thought that the purpose of conda was to be able to switch easily, as well as update and maintain various environments separately.
Perhaps I misunderstood and there's no way around setting my PATH everytime...
In the Windows cmd shell, use the activate and deactivate commands to change the PATH automatically. For instance, if your environment is called python3, run python3 to "activate" (i.e., add to the PATH) the python3 environment. Use deactivate to remove it.

How to customize which Windows $PATH environment variables are imported into Cygwin?

I would like to customize the $PATH variables included in the Cygwin environment, how can I do this? One solution I know of is to add the following line to the end of the Cygwin.bat file:
PATH="/usr/local/bin:/usr/bin:/bin"
By default the shortcut starts bin/mintty.exe, how can I change that default behavior?
All Windows environment variables are included in your Cygwin environment automatically on startup. If you'd like to customize what they are, you can overwrite the whole $PATH variable using a line similar to what you already mentioned in your Cygwin.bat file:
PATH="colon:separated:list:of:all:paths"
Also if you'd like to change which terminal is used by Cygwin, one alternative is rxvt.
Another popular solution seems to be using PuttyCyg to putty directly into your Cygwin installation to get the benefits of the Putty terminal. See the effective-cygwin
GitHub page for setup instructions and more.
See this stackoverflow post for a full list of suggested alternatives to the default Cygwin terminal.

Resources