I'm using python 3 and have many virtual envs using pyvenv on mac osx 10.9.3. In all of them the command ./ runs my python code. In one of my envs the command has stopped working and I can not find anything about how to get it to begin working again.
EDIT: I get permission denied when typing out the whole file instead of tab (i.e. ./manage.py), and when I add sudo it works, but all the other venvs don't require sudo.
I'm searching through pyvenv docs and searching through various bash links but can't get it to restore or know where that shortcut comes from.
When I type python [file] everything works as expected, but I want to restore the ./[file] I know it's going to be something easy but for some reason I can't figure out what to search to get the relevant solution.
When you type ./[tab] and the file you're expecting doesn't come in linux shell, chances are you need to make the file executable:
sudo chmod a+x manage.py
Or you don't have sufficient permissions to access the file:
sudo chown user:group manage.py
(Be careful with the last one because it may lead to unexpected behaviour)
Related
I've installed Superset following the installation guide in the apache superset web page, for Python 3.7.
Even though I can manually start the server, when I'm trying to script the startup steps and cron them, it fails.
The output of the execution is the following:
superset: command not found
I've read the replies of this topic but nothing applies to this case.
I'm not using virtualenv for the installation.
These are the output of the which commands:
ec2-user#Superset-STAGE /var/spool/mail$which python3
/usr/bin/python3
ec2-user#Superset-STAGE /var/spool/mail$which superset
~/.local/bin/superset
ec2-user#Superset-STAGE /var/spool/mail$sudo superset
sudo: superset: command not found
Would you please guide me on how to have my script working without failure? Script looks like below.
superset init
wait
superset runserver -d
Cron runs as root, which means its home directory is /root rather than /home/ec2-user as you expect. This means that it will not be able to find /home/ec2-user/.local/bin/superset because it neither looks for executables in a ~/.local/bin/superset nor is it logged in as a user that has such a directory. A quick fix here is to use the full path, but I would recommend moving the executable to a more appropriate directory such as /usr/local/bin and then adding it to the PATH variable in /etc/profile
I followed the knowledge base on adding this to the .bash_profile
PATH="~/Library/Enthought/Canopy_64bit/User/bin"
export PATH
When I then restart the Terminal, a lot of functions do not work anymore:
X:~ excuvator$ ls
-bash: ls: command not found
X:~ excuvator$ security
-bash: security: command not found
X:~ excuvator$ sudo
-bash: sudo: command not found
However, enpkg and cd still seem to be callable. If I remove that part, stuff works again. Does anyone have any insight to what is happening? I just want to get enpkg running...
You reset PATH, rather than adding to it, so bash doesn't know any place to look for commands other than the single directory you specified. Instead, use one of
PATH=$PATH:~/Library/Enthought/Canopy_64bit/User/bin
or
PATH=~/Library/Enthought/Canopy_64bit/User/bin:$PATH
Which of the two assignments you use depends on whether whether you want the new directory to be the first or last place the shell looks for a named command.
enpkg actually is in that directory, and cd is a shell built-in command, not an external program, so no path lookup is involved.
I'm on a 64-bit Centos 5 Linux. This comes with Python2.4, but I needed 2.6 or higher to get psycopg2. I installed a virtual environment to run Python2.7.3 (based on this http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/) Now things seem to be working well when I'm logged in as root.
But I need to be able to use the virtualenv as a non-root user, joshmoe. (And start/stop postgresql as this other user)
The command for getting into the virtualenv is:
source /root/Python-2.7.3/projectdir/bin/activate
Understandably, when I run this command as joshmoe, I get a permission denied message:
-bash: /root/Python-2.7.3/projectdir/bin/activate: Permission denied
In an attempt to make this command available to joshmoe, I edited /etc/sudoers to include the following line:
joshmoe ALL=NOPASSWD: /root/Python-2.7.3/projectdir/bin/activate
Now from the joshmoe login, when I run:
sudo source /root/Python-2.7.3/projectdir/bin/activate
I get the following:
sudo: source: command not found
It seems pretty clear to me that I'm not using the sudoers file correctly to specify sourcing this file -- I seem to be giving access to that 'activate' file successfully, but not to the built-in source function. Either of following lines give syntax errors in sudoers:
joshmoe ALL=NOPASSWD: source
joshmoe ALL=NOPASSWD: source /root/Python-2.7.3/projectdir/bin/activate
I've found a good many examples of shudders statements. But I can't figure out the syntax that will make this work. I'm hoping once I get this one, I'll be able to give access to statements like 'service postgresql status' and so forth.
Your problem is that you user doesn't have root access to your virutalenv directory. You need to grant the user access for it to work, for example using:
sudo chmod o+x /root # grant access to root directory
sudo chmod o+rX /root/Python-2.7.3 -R # recursively grant access to everything in Python-2.7.3
source isn't a program, it's a shell butiltin which causes a script to be sourced in the current shell. sudo can only execute programs, not shell builtins, functions or aliases, that's why you get that error.
You can't run source as as sudo source; it's a built-in command for bash, not a program. What you want to do here is probably start a new shell as superuser using sudo -s.
I'm new to django and currently going through the main tutorial. Even though it was working earlier, when I do python manage.py runserver OR python manage.py -h OR with any other command, the shell doesn't output anything. Wondering what I'm doing wrong.
The problem is that the first line in manage.py breaks the file on windows.
The first line should look like this:
#!/usr/bin/env python
Removing it will fix the issue.
First, check if python is fully installed by typing "python" in a shell.
Then you should try python manage.py runserver inside your django project. If you don't have any django project, try creating one by typing django-admin.py startproject mysite. If nothing is displayed in your shell, you must have installed Django the wrong way.
Please refer to Django Documentation at https://docs.djangoproject.com/en/1.4/intro/install/
If you had your server running till one point and a certain action/change broke it, try going back to the previous state.
In my case there was an email trigger which would put the system in an invalid state if email doesn't go through. Doing git stash followed by selectively popping the stash and trying the runserver helps narrow down the problem to a particular file in your project.
Please try this.
Uninstall Python.
Go inside C drive and search Django. You will get many Django related files.
Delete every Django file. đ don't delete your Django files.
Install Python.
It's worked for me.
if you created a virtual environment then activate it. you can try this command(in virtual environment directory) if you're using windows os:
.\Scripts\activate
On Ubuntu works for my by running manage.py as script:
./manage.py runserver
Just stuck with the same problem. Found a solution that works, but tedious.
You need to know the location of the python.exe file in your computer. It is usually
C:/Users/USERNAME/AppData/Local/Programs/Python//python.exe
Modify as required and run the following in CMD,
C:/Users/USER1/AppData/Local/Programs/Python/Python38-32/python.exe
F:/mysite/manage.py runserver
Hope this works :)
if you are using Redis Server on Windows, check it out if Redis Server is running, I had same problem and realized my Redis Server was not running, I ran it and now my manage.py commands work fine.
The same happened with me also, but this issue is a minor one as it happens if you have multiple versions of Python on your system, you can select a specific Python version by running python3 or whichever version you want.
SO you should start from the beginning, uninstall Django first then,
create a virtual environment, decide upon a directory where you want to place it, and run the venv module as a script with the directory path:
for e.g:
python3 -m venv tutorial-env
//This will create the tutorial-env directory if it doesnât exist, and also create directories inside it
Once youâve created a virtual environment, you may activate it.
On Windows, run:
tutorial-env\Scripts\activate.bat
On Unix or MacOS, run:
source tutorial-env/bin/activate
Now,
In the command prompt, ensure your virtual environment is active, and execute the following command:
...> py -m pip install Django
NOTE:
If django-admin only displays the help text no matter what arguments it is given, there is probably a problem with the file association in Windows. Check if there is more than one environment variable set for running Python scripts in PATH. This usually occurs when there is more than one Python version installed.
Another solution, if you can, is to upgrade Django
pip install django --upgrade
Oftentimes one will get other unrelated issues to solve that are linked with the upgrade but once all is fixed the server should run just fine.
If you can't upgrade Django, this problem also happens when the code was built using Python 2.x and you're locally using Python 3.x.
The quicker fix in that case is to uninstall Python 3.x from your machine and make sure Python 2.x was added to the path. I've seen some developers setting up alias in PowerShell to have more than one version in the environment too.
I think the problem is in manage.py file (50%), check it with an another file that is correct.
I stupidly downloaded python 3.2.2 and since then writing 'python' in the terminal yields 'command not found'. Also, when starting the terminal I get this:
Last login: Wed May 2 23:17:28 on ttys001
-bash: export: `folder]:/Library/Frameworks/Python.framework/Versions/2.7/bin:/opt/local/bin:/opt/local/sbin:/usr/local/git/bin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/Applications/android-sdk-mac_86/tools:/Applications/android-sdk-mac_86/platform-tools:/usr/local/git/bin:/usr/X11/bin:/usr/local/ant/bin': not a valid identifier
Why the Android SDK folder is there is beyond me. It's all jazzed up. Any ideas how can I remove the offending file, folder or fix his problem? I've checked the System Profiler and python 2.6.1 and 2.7.2.5 shows up.
If the binary was not overridden it's typically located in
/System/Library/Frameworks/Python.framework/Versions/X.X/bin/python
where X.X is your version (probably 2.7) if it's not located there it could be sometimes found in
/Library/Frameworks/Python.framework/Versions/X.X/bin/python
If you find the right binary and can run it, go ahead and start symlinking it where you need to and making the necessary patches. My first piece of advice would be changing your Current to point to the old version.
sudo ln -s /System/Library/Frameworks/Python.framework/Versions/X.X /System/Library/Frameworks/Python.framework/Versions/Current
or
sudo ln -s /Library/Frameworks/Python.framework/Versions/X.X /Library/Frameworks/Python.framework/Versions/Current
Something got messed up in your $PATH. Have a look in ~/.profile, ~/.bashrc, ~/.bash_profile, etc., and look for a line starting with export that doesn't end cleanly.
A very ugly solution to your profile problem since $PATH seems to be very wrong (as was mentioned by blahdiblah)
/bin/cp ~/.profile /tmp/bkup_profile
/bin/cat /tmp/bkup_profile | /usr/bin/grep -v "PATH" > ~/.profile
Open a new terminal and see if you can run commands normally try ls, echo, sudo for example.