PIP command doesn't work inside virtual environment - python

The interpreter I use is
and it works in virtual environment. I have both anaconda and python interpreter installed in my system
But if I want to install something using pip for instance "Flask" then it happens
I am using Linux Mint 18.1 Serena"
And the way I tried to create the virtual environment is
Lastly there is no space in the directories where I tried to create virtual environment
Then I tried this link
Specifically the following commands
All those things didn't solve my problem and lastly I ended with the following errors each time I open my shell
Then I change my source of bashrc & bashrc-org to
virtualenv
export WORKON_HOME=~/virtualenvs
source /home/cryptosilicon/anaconda3/bin/python
Now get the following error
How do I correct the error and make the pip work inside virtual environment ?

I just solved (or at least found a work-around) for a similar problem.
I am using Linux Mint 18 and python 3.
I was trying to install a dependency inside a Python virtual environment using pip and it would fail (and actually pretty much mess up my whole virtual env).
The message was : "bad interpreter: No such file or directory".
But I noticed that the referenced path was actually truncated at the first space.
So I tested an virtual env in a folder for which path there is no space and it worked.

Related

PyCharm doesn't recognize packages installed via Terminal when environment is used in PyCharm in Pop_OS Linux

I'm using Pop_OS! Linux. Whenever I make a Python Virtual Environment using mkvirtualenv and then pip install packages into it, that environment does not work when I reference it inside pycharm. I set up virtual environments using virtualenv and virtualenvwrapper.
The workaround I've found is to build any virtual environment you need to use inside of PyCharm inside of pycharm, or using the terminal inside of PyCharm. I'm annoyed it doesn't seem compatible with my native terminal, and can't figure out why. I even get slightly different python versions by running python --version both inside the PyCharm terminal and in the native linux terminal, while inside the same virtual environment! It's like Pycharm isn't reading the same information out of the python environment directory as my terminal is.
What is going on here, and how do I harmonize PyCharm with the rest of my linux machine? I'm also new to Pop_OS! Trying it out for the first time is an adventure.
IDK if that will work, but maybe if you install your packages via the "Python packages" tab in PyCharm (down left -> add package next to the research bar that appeared), PyCharm will see them while it installed them itself.

no python at "C:\Users\AccountName\AppData\Local\Programs\Python\Python38-32\python.exe" error in VsCode

I was running the Django project without any problems. Until I reinstalled Windows and then reinstalled vscode! Now that I am running the Django project, vscode shows the following error:
Error: no python at C:\Users\AccountName\AppData\Local\Programs\Python\Python38-32\python.exe
This might be occurs if the python directory still in the environment variables path list.
First remove python entry from the environment variables path if exists.
Also there will be a chance for virtual environments in your project. If the virtual environment is setup in the uninstalled python version then you will get the same error message.
So, remove the virtual environments which is created under the uninstalled python. It can be done by deleting the virtual environment folder from your system.
Edit pyvenv.cfg
home = C:\Users\UserName\AppData\Local\Programs\Python\Python38-32
include-system-site-packages = false
version = 3.8.3
When I edited this file after checking the file path on my computer, it worked for me.
Based on the information you provided, it is recommended that you check the Python environment variables.
Since the Windows system is reinstalled, the environment variables are restored to the default settings. Therefore, please add Python environment variables:
Or you can reinstall Python and check the "Add Python 3.8 to PATH" option, which will automatically add Python environment variables.
You could also refer to : Python environment variables.
It's very simple
Delete your dbsqite3 file from your project folder
Open your project in CMD
install virtual environment pip install virtaualenv
virtualenv .
\scripts\activate
python manage.py runserver
and play with your code
you shared.
This works for Pycharm, It did to me
From your projects folder, delete the 3 folders i.e. .ide,venv, and the third folder i think.. do not touch the projects or scripts you created. After wards, go to Pycharm and configure python interpreter again. This will now enable you to run yo scripts now with no prob
make sure to install virtualenv befor install python
check wheather django is installed (if your are using django framework).
pip install django

zsh: commands not working for pip, conda, python

So here is my story:
As we know macos comes with pyhton 2.7 preinstalled. Years ago, I installed python 3.7.0 and all going good. I started working with Tensorflow and during that time tensorflow wasn't compatible with 3.7.0 so switch the version to 3.6.6 somehow :). After some time i installed anaconda and it installed 3.7.3.
At this point:
When i open my python IDLE shell, it runs on 3.6.6
anaconda Jupiter notebook shows 3.7.3.
Then i learned to create virtual environments through terminal and i use following code to create virtual environment:
pip install virtualenv
virtualenv project_env
And after i activate the virtual environment the python version it shows is 3.7.3.
Then recently i changed the terminal shell to zsh and now everything is kind of messed up. I'm
Terminal can't find conda commands. How to fix that?
Now i can't create virtual environment through virtualenv project_env. It says command not found. Why? It use to create virtual environments with python 3.7.3.
Now to create virtual environment i use python3 -m venv project_env this creates the virtual environment with python 3.6.6. If i use python3.7 -m venv project_env it creates environment with python 3.7.0.
I can't find a way to create virtual environments with python 3.7.3.
I need help with above troubles caused after installing zsh and help with accessing python versions wherever i need. How do i update python version 3.7.0 to latest or any specific version like 3.7.3. Hows python 3.8.4 to use, i mean like i had trouble importing tensorflow in python 3.7.0.
I hope you will understand my trouble and searched a lot for solutions. I'm so confused right now, couldn't even figure out the title of my problem.
Based on the fact your shell can't find conda now, you should look at your "path" environment variable. Whenever you change from one shell to another, you need to look at and possible create or modify the files the shell uses upon startup. These files setup your environment (PATH, PYTHONPATH, etc), create aliases, etc. You may need to create the .zshrc, .zprofile, .zlogin etc files and add the same settings as your previous shell's startup files.
Example:
If you used the bash shell previously you would need to modify the .zshrc file to include your settings in the .bashrc file. Syntax may be different, so a straight copy may or may not work.
Try this as a quick temporary fix (may or may not work, depending on your current ~/.profile settings:
Create a ~/.zprofile file with this code inside:
emulate sh
. ~/.profile
emulate zsh
references:
https://superuser.com/questions/187639/zsh-not-hitting-profile
http://zsh.sourceforge.net/Intro/intro_3.html

Starting Matlab engine in anaconda virtual environment returns 'Segmentation fault (core dumped)'

I've installed the official MATLAB Engine by following the instructions from the answer to Anaconda install Matlab Engine on Linux to an Anaconda virtual environment running Python3.5. I can now import matlab and matlab.engine without receiving errors. However, when I try:
matlab.engine.start_matlab(), I get 'Segmentation fault (core dumped)'
I've tried setting LD_LIBRARY_PATH from within the conda environment (in case that is even relevant): export LD_LIBRARY_PATH=/System/Library/Frameworks/Python.framework/Versions/Current/lib:$LD_LIBRARY_PATH, but to no avail. The path doesn't exist either as far as I'm aware, so I've also tried export DYLD_LIBRARY_PATH=path_to_anaconda3/envs/myEnv/lib:$LD_LIBRARY_PATH
So how can I start the matlab engine/call Matlab scripts from Python from within a Anaconda virtual environment?
I'm on Ubuntu, by the way
Short answer: there were two problems that needed to be fixed
$LD_LIBRARY_PATH should not contain a path to the Anaconda installation. Adding such a path is discouraged according to the conda documentation: https://conda.io/docs/building/shared-libraries.html, but some packages may do so anyways, causing the segmentation error.
A symbolic link is needed from a libpythonXXX.dylib file of the right version to /usr/lib/, so that MATLAB can find the right Python
Long answer: complete installation instructions for using MATLAB Engine with Anaconda
Install a MATLAB version that supports the Python you want to use. Ensure that this particular MATLAB installation is activated
Open a terminal and go to the folder containing the Python engine of the MATLAB installation: cd "/usr/local/MATLAB/R2017a/extern/engines/python"
Run setup.py with the Python version you want to use, and prefix the Anaconda environment location: sudo python3.5 setup.py install --prefix="/your_path_to_anaconda3/envs/your_env". At this point you should be able to import matlab and matlab.engine from within the Python of your Anaconda environment, but, in my case, starting the engine gave the segmentation error.
Find the libpython file of the right version. Your Anaconda environment should contain it: find /your_path_to_anaconda3/envs/your_env/ -name libpython*. In my case this returned:
/.../lib/libpython3.so
/.../lib/python3.5/config-3.5m/libpython3.5m.a
/.../lib/libpython3.5m.so.1.0
/.../lib/libpython3.5m.so
As I wanted to use it with python 3.5, I went with libpython3.5m (I don't know why the 'm' is there). Make a symbolic link from the .dylib version of this file to /usr/lib: sudo ln -s /your_path_to_anaconda3/envs/your_env/lib/libpython3.5m.dylib /usr/lib. Note that you can only have one link called libpython3.5m.dylib in /usr/lib. So if you have multiple Anaconda environments using the same version of Python, you only need to set up this link once to whichever one. Remember not to delete this environment though, as that would break the link for all other environments relying on it.
Start a new terminal (!) and activate your Anaconda environment: source activate your_env. Check within your Anaconda environment whether LD_LIBRARY_PATH contains any references to the Anaconda environment echo $LD_LIBRARY_PATH. If so, ensure that it no longer does: export LD_LIBRARY_PATH=only_paths_you_do_want_to_keep_separated_by_a_colon. This export action needs to be repeated whenever you activate your Anaconda environment, so you may want to look into more permanent means of setting it. However, in my case (apart from the fact I had been adding it myself in the hope this would improve things) the path was actually added by pygpu, so I ended up resetting LD_LIBRARY_PATH from my python script (so far without noticing ill effects).

PTVS cant find Python interpreter?

I just copied my Flask project from one machine to another. I have same version of Python installed on both the machines. When I loaded the project in the new machine, it said my virtual environment is unavailable. So I initially tried to install it from requirements.txt file but it failed without any helpful error message.
So I deleted the virtual env in Visual Studio and tried to create another one. Now it complains that it cannot find any Python interpreters on my machine. I tried uninstall/reinstall Python but it didn't work. Also, the Python location is added in the PATH environment variable and all the modules in the requirements.txt file are downloaded from pip individually.
So the modules are installed, python is installed and the project is there but the virtual env won't setup because of the below reason. Any way that I can fix this ? This is PTVS15 and Python 3.6.1
Fixed it myself. I went ahead and added the environment manually by specifying the Python installation paths in the Add Environment tab. It took a while to detect the interpreter even in this way but it finally worked. I am now able to build my app.

Categories